Constexpr compile error using std::acos with clang++ not g++

后端 未结 1 912
闹比i
闹比i 2021-01-05 06:05

I want to experiment with migrating a project from gcc to clang++. I admit ignorance on my part, I\'m not sure why the following bit of code

template 

        
相关标签:
1条回答
  • 2021-01-05 06:46

    Clang is correct here, we are not allowed to use acos in a constant expression.

    The issue is that acos is not marked constexpr in the standard but gcc treats some functions not marked in the standard including acos as constexpr. This is a non-conforming extension and should eventually be fixed in gcc.

    Builtin functions are often used to constant fold and we can see if we use -fno-builtin with gcc it disables this non-conforming behavior and we will receive the following error:

    error: call to non-constexpr function 'double acos(double)'
    constexpr T pi{std::acos(T(-1.0))};
                             ^
    
    0 讨论(0)
提交回复
热议问题