5

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?

2

2 Answers 2

7

This is GCC bug 86678, and was fixed just a few days ago.

Sign up to request clarification or add additional context in comments.

Comments

0

If you like me have this issue, but you can't upgrade the compiler nor change the code. A quick fix is to have the compiler remove the asserts by adding the NDEBUG flag to the compiler:

  • gcc/clang: -DNDEBUG
  • msvc: /DNDEBUG

Maybe this can save someone a bit of time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.