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