comparison gcc/testsuite/g++.dg/cpp2a/constexpr-try4.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 // PR c++/89513
2 // { dg-do compile { target c++14 } }
3 // { dg-options "" }
4
5 constexpr int foo ()
6 try { // { dg-warning "function-try-block body of 'constexpr' function only available with" "" { target c++17_down } }
7 int a = 1;
8 for (int i = 0; i < 10; i++)
9 a += i;
10 return a;
11 } catch (...) {
12 return -1;
13 }
14
15 constexpr int bar ()
16 try { // { dg-warning "function-try-block body of 'constexpr' function only available with" "" { target c++17_down } }
17 int a = 0;
18 for (int i = 0; i < 9; i++)
19 try { // { dg-warning "'try' in 'constexpr' function only available with" "" { target c++17_down } }
20 a += i;
21 } catch (int) {
22 return -1;
23 }
24 return a;
25 } catch (...) {
26 return -2;
27 }
28
29 constexpr bool baz ()
30 {
31 try { return true; } catch (...) { return false; } // { dg-warning "'try' in 'constexpr' function only available with" "" { target c++17_down } }
32 }
33
34 struct S {
35 constexpr S () try : m (1) // { dg-warning "function-try-block body of 'constexpr' constructor only available with" "" { target c++17_down } }
36 {
37 try { // { dg-warning "'try' in 'constexpr' function only available with" "" { target c++17_down } }
38 m += 2;
39 } catch (int) {
40 m = -1;
41 }
42 } catch (...) {
43 m = -2;
44 }
45 int m;
46 constexpr int get () const { return m; }
47 };
48
49 struct T {
50 constexpr T ()
51 try { // { dg-warning "function-try-block body of 'constexpr' constructor only available with" "" { target c++17_down } }
52 } catch (...) {
53 }
54 };
55
56 static_assert (foo () == 46, "");
57 static_assert (bar () == 36, "");
58 static_assert (baz (), "");
59 constexpr S s;
60 static_assert (s.get () == 3, "");
61 constexpr T t;