1 // PR c++/89513
2 // { dg-do compile { target c++11 } }
3
foo()4 constexpr bool foo ()
5 try { // { dg-error "function-try-block body of 'constexpr' function only available with" "" { target c++17_down } }
6 return true;
7 } catch (...) { // { dg-error "compound-statement in 'constexpr' function" "" { target c++11_only } }
8 return false;
9 } // { dg-error "body of 'constexpr' function" "" { target c++11_only } }
10
bar()11 constexpr bool bar ()
12 try { // { dg-error "function-try-block body of 'constexpr' function only available with" "" { target c++17_down } }
13 try { // { dg-error "'try' in 'constexpr' function only available with" "" { target c++17_down } }
14 return true; // { dg-error "compound-statement in 'constexpr' function" "" { target c++11_only } .-1 }
15 } catch (int) { // { dg-error "compound-statement in 'constexpr' function" "" { target c++11_only } }
16 return false;
17 }
18 } catch (...) { // { dg-error "compound-statement in 'constexpr' function" "" { target c++11_only } }
19 return false;
20 } // { dg-error "not a return-statement" "" { target c++11_only } }
21
baz()22 constexpr bool baz ()
23 {
24 try { return true; } catch (...) { return false; } // { dg-error "'try' in 'constexpr' function only available with" "" { target c++17_down } }
25 } // { dg-error "not a return-statement" "" { target c++11_only } }
26 // { dg-error "compound-statement in 'constexpr' function" "" { target c++11_only } .-2 }
27
28 struct S {
SS29 constexpr S () try : m (1) // { dg-error "function-try-block body of 'constexpr' constructor only available with" "" { target c++17_down } }
30 {
31 try { // { dg-error "'try' in 'constexpr' function only available with" "" { target c++17_down } }
32 } catch (int) { // { dg-error "compound-statement in 'constexpr' function" "" { target c++11_only } }
33 } // { dg-error "compound-statement in 'constexpr' function" "" { target c++11_only } .-2 }
34 } catch (...) { // { dg-error "'constexpr' constructor does not have empty body" "" { target c++11_only } }
35 }
36 int m;
37 };
38
39 struct T {
TT40 constexpr T ()
41 try { // { dg-error "function-try-block body of 'constexpr' constructor only available with" "" { target c++17_down } }
42 } catch (...) { // { dg-error "compound-statement in 'constexpr' function" "" { target c++11_only } }
43 }
44 };
45