C++11 C++;11 constexpr+;没有例外';t判断函数是否为编译时常量函数

C++11 C++;11 constexpr+;没有例外';t判断函数是否为编译时常量函数,c++11,expression,constants,constexpr,noexcept,C++11,Expression,Constants,Constexpr,Noexcept,我在cppreference网站上看到了这个例子,但是运行结果并不是预期的 页面上写着: 由于noexcept运算符始终为常量表达式返回true,因此可以使用它检查constexpr函数的特定调用是否采用常量表达式分支: 但我尝试过: $cat testNoexcept.cpp #include<stdio.h> constexpr int f1(); constexpr int f2(){return 1;} int main(){ constexpr bool b1=n

我在cppreference网站上看到了这个例子,但是运行结果并不是预期的

页面上写着:

由于noexcept运算符始终为常量表达式返回true,因此可以使用它检查constexpr函数的特定调用是否采用常量表达式分支:


但我尝试过:

$cat testNoexcept.cpp
#include<stdio.h>
constexpr int f1();
constexpr int f2(){return 1;}
int main(){
    constexpr bool b1=noexcept(f1());//false
    constexpr bool b2=noexcept(f2());//true
    printf("%d,%d\n",b1,b2);
    return 0;
}

$g++ testNoexcept.cpp -std=c++14&&./a.out
0,0
$cat testNoexcept.cpp
#包括
constexpr int f1();
constexpr int f2(){return 1;}
int main(){
constexpr bool b1=noexcept(f1());//false
constexpr bool b2=noexcept(f2());//true
printf(“%d,%d\n”,b1,b2);
返回0;
}
$g++testNoexcept.cpp-std=c++14&&./a.out
0,0

两者都是错误的。为什么?是网站错了,还是我的理解错了?

哪个编译器?它在这里工作:@Viatorus:它会发出叮当声打印
0,0
。可能是个bug。它适用于gcc。如果您添加noexcept,它也可以在clang中工作…@VittorioRomeo clang未实现此功能: