|
|
|
|
|
by robotresearcher
1167 days ago
|
|
You're both right, but you're talking about different things. If you use the same values at run time as you use in the tests, the tests predict the behavior as desired. If you use different values at run time as you use in the tests, the tests do not predict the behavior as desired. |
|
The GP post is explicitly claiming that the values don't matter, and that per the standard a constexpr function should be guaranteed by the compiler to be incapable of producing UB (or else compilation should fail and it should not be allowed to be declared constexpr). This is simply false. Here is the GP statement:
>> That is, conditional constepxr code that depends on values and could produce UB is not valid constexpr code, and a compiler is not supposed to compile it. [emphasis mine]
> If you use the same values at run time as you use in the tests, the tests predict the behavior as desired.
Even this is not fully guaranteed by the standard, as core constant expressions must only be guaranteed not to invoke core language UB. They may still be considered core constant expressions and evaluated at compile time even if they exhibit standard library UB (e.g. if they are not respecting some preconditions of an std::vector method).