Throw in constexpr function
The following piece of code compiles under clang++ 3.7.0 but is denied by g++ 5.3.1. Both have -std=c++14 option. Which compiler is correct? Anyone knows where in the standard talks about this? Thanks. #include <stdexcept> using namespace std; constexpr int f(int n) { if (n <= 0) throw runtime_error(""); return 1; } int main() { char k[f(1)]; } Output $ g++ -std=c++14 c.cpp c.cpp: In function ‘constexpr int f(int)’: c.cpp:7:1: error: expression ‘<throw-expression>’ is not a constant-expression } ^ $ clang++ -std=c++14 c.cpp $ $ g++ -v Using built-in specs. COLLECT_GCC=/usr/bin/g++ COLLECT_LTO_
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.