3

I see this example from cppreference website, but the running result was not anything expected.(http://en.cppreference.com/w/cpp/language/constexpr)

The page says:"

Because the noexcept operator always returns true for a constant expression, it can be used to check if a particular invocation of a constexpr function takes the constant expression branch:"


But I experimented this:

$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

Both are false. Why? Is the web-site wrong, or my understanding is wrong?

cpplearner
  • 13,776
  • 2
  • 47
  • 72
Troskyvs
  • 7,537
  • 7
  • 47
  • 115

0 Answers0