Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wcatch-value-2.C

raw
1 // Explicit { dg-require-effective-target exceptions_enabled } to avoid verify compiler messages FAILs for '-fno-exceptions'.
2 // { dg-options "-Wcatch-value=2" }
3
4 struct A { virtual ~A() {} };
5 struct B : A {};
6 struct C {};
7 struct D : C {};
8
9 void foo()
10 {
11 try {}
12 catch (D) {} // { dg-warning "10:catching type" }
13 catch (C) {} // { dg-warning "10:catching type" }
14 catch (B) {} // { dg-warning "10:catching polymorphic type" }
15 catch (A) {} // { dg-warning "10:catching polymorphic type" }
16 catch (A*) {}
17 catch (int) {}
18
19 try {}
20 catch (D&) {}
21 catch (C&) {}
22 catch (B&) {}
23 catch (A&) {}
24 catch (A*) {}
25 catch (int&) {}
26 }
27
28 template<typename T> void foo1()
29 {
30 try {}
31 catch (T) {} // { dg-warning "10:catching" }
32 }
33
34 template<typename T> void foo2()
35 {
36 try {}
37 catch (T*) {}
38
39 try {}
40 catch (T&) {}
41
42 try {}
43 catch (const T&) {}
44 }
45
46 void bar()
47 {
48 foo1<int&>();
49 foo1<const A&>();
50 foo1<B&>();
51 foo1<const C&>();
52 foo1<D&>();
53
54 foo1<int>();
55 foo1<A>(); // { dg-message "required" }
56 foo1<B>(); // { dg-message "required" }
57 foo1<C>(); // { dg-message "required" }
58 foo1<D>(); // { dg-message "required" }
59
60 foo2<int>();
61 foo2<A>();
62 foo2<B>();
63 foo2<C>();
64 foo2<D>();
65 }