News for hackers. Stuff that matters.
Re:C++17 constexpr everything, or as much as the compiler can by phkahler on Thursday December 28, 2017 @07:37AM (#16021686)
What about debugging? If the code to generate the data is large and complex, how do you debug it when it only runs at compile time? Is the solution to start with two programs like the author and then merge them? That still seems like a maintainability issue.
Re:C++17 constexpr everything, or as much as the compiler can by AlexeyBrin on Thursday December 28, 2017 @07:45AM (#16021716)
A constexpr function can be used with a non-constexpr argument in which case the compiler will keep the function in the compiled code and you can use it as a normal function.

In the context of the linked article, take the first example and modify it, by reading a number at runtime with std::cin and call factorial or fibonacci with this number as an argument.

Something like this https://godbolt.org/g/CT5M6f

Re:C++17 constexpr everything, or as much as the compiler can by dawg on Thursday December 28, 2017 @07:48AM (#16021726)
In D which has CTFE support since ages, you'd debug such functions by invoking them at runtime. https://tour.dlang.org/tour/en/gems/compile-time-function-ev... There are also tools to print values at compile time.

A compile time debugger for the CTFE interpreter is on our extended feature list for the current interpreter rewrite, but it's less of a priority atm.

Re:C++17 constexpr everything, or as much as the compiler can by ben-schaaf on Thursday December 28, 2017 @02:38PM (#16024323)
Sadly it's fairly easy to write a function that fails at compile time but runs fine at runtime. For those situations there's at least `pragma(msg,`
Re:C++17 constexpr everything, or as much as the compiler can by humanrebar on Thursday December 28, 2017 @10:16AM (#16022371)
> ...how do you debug it when it only runs at compile time?

I prefer to unit test my constexpr logic with a bunch of static assertions in a cpp file. You could put them in with the code being debugged, but having them separate keeps the header files lighter weight with no real downside assuming you have CI or something set up.

Re:C++17 constexpr everything, or as much as the compiler can by masklinn on Thursday December 28, 2017 @07:57AM (#16021759)
constexpr don't have to run at compile-time, they can do so.

So you can use regular tests/debugging to debug your function.

Re:C++17 constexpr everything, or as much as the compiler can by 112233 on Thursday December 28, 2017 @09:45AM (#16022220)
what about cases when regular debugging is printf/assert/static_assert?
Re:C++17 constexpr everything, or as much as the compiler can by jcelerier on Thursday December 28, 2017 @07:57AM (#16021758)
> If the code to generate the data is large and complex, how do you debug it when it only runs at compile time?

that's up to the compiler actually. For instance, in debug mode visual studio skips constexpr and does everything at runtime (which sucks if you depend on stuff being constexpr).

Re:C++17 constexpr everything, or as much as the compiler can by nurettin on Thursday December 28, 2017 @07:43AM (#16021712)
You could use something like #ifdef NDEBUG #define MY_CONSTEXPR #else #define MY_CONSTEXPR constexpr so when you are running the debug build, everything is debuggable.
Re:C++17 constexpr everything, or as much as the compiler can by skrebbel on Thursday December 28, 2017 @08:51AM (#16021957)
That makes the compiler not complain when your constexpr isn't a valid constexpr.
Re:C++17 constexpr everything, or as much as the compiler can by nurettin on Thursday December 28, 2017 @10:29AM (#16022470)
Until you make release
Re:C++17 constexpr everything, or as much as the compiler can by mike_hock on Thursday December 28, 2017 @10:35AM (#16022510)
After 3 months of development all I have to do is make release and ...
Re:C++17 constexpr everything, or as much as the compiler can by ryandrake on Thursday December 28, 2017 @11:23AM (#16022939)
If you guys are going three days without testing a release build (let alone three months), then you probably have bigger issues to work through than what constexpr is doing...
Re:C++17 constexpr everything, or as much as the compiler can by geezerjay on Thursday December 28, 2017 @01:46PM (#16023939)
The hypothetical odds of having bigger issues does not justify creating additional issues for no reason at all.
Re:C++17 constexpr everything, or as much as the compiler can by nurettin on Friday December 29, 2017 @02:05PM (#16031227)
which is why they should build release more often.