assert in constexpr function

China☆狼群 提交于 2020-02-04 23:53:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!