The following valid test case was reduced from the invalid one submitted with bug 70377. GCC rejects the constexpr function simple_find because it contains a throw statement even though the statement is not evaluated in the (constexpr) contexts the function is called. Clang 5.0 and EDG eccp 4.13 both accept the program. $ cat t.C && gcc -Wall -Wextra -Wpedantic t.C struct array { int a [3]; constexpr const int& operator[](int i) const { return a[i]; } }; constexpr int simple_find (const array &a, int x) { for (int i = 0; i != 3; ++i) if (a[i] == x) return i; throw; } static constexpr array some_ints { { 10, 11 } }; static_assert (simple_find (some_ints, 10) == 0, "#1"); static_assert (simple_find (some_ints, 11) == 1, "#2"); t.C: In function ‘constexpr int simple_find(const array&, int)’: t.C:14:3: error: expression ‘<throw-expression>’ is not a constant expression throw; ^~~~~ t.C: At global scope: t.C:19:1: error: non-constant condition for static assertion static_assert (simple_find (some_ints, 10) == 0, "#1"); ^~~~~~~~~~~~~ t.C:19:28: error: ‘constexpr int simple_find(const array&, int)’ called in a constant expression static_assert (simple_find (some_ints, 10) == 0, "#1"); ~~~~~~~~~~~~^~~~~~~~~~~~~~~ t.C:20:1: error: non-constant condition for static assertion static_assert (simple_find (some_ints, 11) == 1, "#2"); ^~~~~~~~~~~~~ t.C:20:28: error: ‘constexpr int simple_find(const array&, int)’ called in a constant expression static_assert (simple_find (some_ints, 11) == 1, "#2"); ~~~~~~~~~~~~^~~~~~~~~~~~~~~
Simpler test case: void foo( bool ok ) { if( ok ) return; throw; } fails to compile with g++ 6.3.0 and g++ 7.1.0
> void foo( bool ok ) { ^constexpr
*** Bug 82572 has been marked as a duplicate of this bug. ***
*** Bug 83242 has been marked as a duplicate of this bug. ***
*** Bug 86192 has been marked as a duplicate of this bug. ***
*** Bug 86207 has been marked as a duplicate of this bug. ***
Comment 1 compiles fine since r264171.
Fixed.