vendredi 1 janvier 2016

Is this error message correct: non-type template argument is not a constant expression

The following program compiles with GCC 5.2, but not with clang 3.6:

constexpr bool flag();

template <bool b = flag()>
constexpr void test() 
{ 
    return b;
}

int main() 
{
}

The error message I get with clang is:

main.cpp:3:24: error: non-type template argument is not a constant expression
    template <bool b = flag()>
                       ^~~~~~
main.cpp:3:24: note: undefined function 'flag' cannot be used in a constant expression
main.cpp:1:20: note: declared here
    constexpr bool flag();
                   ^
main.cpp:4:20: error: no return statement in constexpr function
    constexpr bool test() 
                   ^

My question is: Who's right? Or, in other words: Is the program ill-formed?

Aucun commentaire:

Enregistrer un commentaire