Skip to content

More compile-time testing with C++14

Dan Eble requested to merge dev/eble/cpp-14 into master

Yaffut: allow some checks in constexpr functions

This allows using these checks in tests that can be evaluated at either compile time or run time. When evaluating at compile time, it is an error if one these checks throws an exception.

Some benefits of compile-time testing:

  • It proves that there is no undefined behavior in the tested cases. (The compiler is required to check.)
  • It shows that the tested case can really be evaluated at compile time.
  • It detects failures earlier than run-time testing.

A drawback of compile-time testing is that when a test fails, you don't have an interactive debugger in which to step through the code leading up to the failure. This change facilitates writing compile-time tests that can be debugged relatively easily with a quick change to evaluate them at run time instead.

Also, whether a function can be evaluated at compile time depends on its inputs. This change facilitates writing tests that can be evaluated at compile time in some cases and at run time in others.

I have included some exemplary changes to Direction and Drul_array. This just is low-hanging fruit that I found in a quick scan when I investigated enabling C++14 support a few weeks ago. Probably, there are more places where constexpr could be added. Probably, some of the older static_assert tests that were previously limited by C++11 could be updated to use Yaffut checks. I am not likely to come back to this for a couple of months at least, so I decided not to wait any longer before posting this.

Edited by Dan Eble

Merge request reports