问题
In trying to work out why I was getting a certain compile error, I came up with the following minimal example:
constexpr void Test(bool test)
{
if (test)
return;
assert(false);
}
This compiles without issue with every version of clang I tried (3.7+), but fails with gcc (tested 5-8), with
error: call to non-‘constexpr’ function ‘void __assert_fail(const char*, const char*, unsigned int, const char*)’
From my understanding, the function should be able to be constexpr
because there is a set of argument values for which the function can be evaluated at compile time.
Is my understanding wrong, or is gcc incorrect in failing to compile this?
回答1:
This is GCC bug 86678, and was fixed just a few days ago.
来源:https://stackoverflow.com/questions/52397841/assert-in-constexpr-function