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