1 // RUN: %clang_cc1 %s -fsyntax-only -verify -Wreturn-type -Wmissing-noreturn -Wno-unreachable-code
2 // RUN: %clang_cc1 %s -fsyntax-only -std=c++11 -verify -Wreturn-type -Wmissing-noreturn -Wno-unreachable-code
4 // A destructor may be marked noreturn and should still influence the CFG.
5 void pr6884_abort() __attribute__((noreturn));
7 struct pr6884_abort_struct {
8 pr6884_abort_struct() {}
9 ~pr6884_abort_struct() __attribute__((noreturn)) { pr6884_abort(); }
12 struct other { ~other() {} };
14 // Ensure that destructors from objects are properly modeled in the CFG despite
15 // the presence of switches, case statements, labels, and blocks. These tests
16 // try to cover bugs reported in both PR6884 and PR10063.
17 namespace abort_struct_complex_cfgs {
19 switch (x) { default: pr6884_abort(); }
22 switch (x) default: pr6884_abort_struct();
25 switch (x) { default: pr6884_abort_struct(); }
27 int f2_positive(int x) {
28 switch (x) { default: ; }
29 } // expected-warning {{control reaches end of non-void function}}
31 switch (x) { default: { pr6884_abort_struct(); } }
34 switch (x) default: L1: L2: case 4: pr6884_abort_struct();
37 switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); }
40 switch (x) default: L1: L2: case 4: { pr6884_abort_struct(); }
43 // Test that these constructs work even when extraneous blocks are created
44 // before and after the switch due to implicit destructors.
47 switch (x) default: pr6884_abort_struct();
51 switch (x) { default: pr6884_abort_struct(); }
53 int g2_positive(int x) {
55 switch (x) { default: ; }
56 } // expected-warning {{control reaches end of non-void function}}
59 switch (x) { default: { pr6884_abort_struct(); } }
63 switch (x) default: L1: L2: case 4: pr6884_abort_struct();
67 switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); }
71 switch (x) default: L1: L2: case 4: { pr6884_abort_struct(); }
74 // Test that these constructs work even with variables carrying the no-return
75 // destructor instead of temporaries.
78 switch (x) default: pr6884_abort_struct a;
82 switch (x) { default: pr6884_abort_struct a; }
86 switch (x) { default: { pr6884_abort_struct a; } }
90 switch (x) default: L1: L2: case 4: pr6884_abort_struct a;
94 switch (x) default: L1: { L2: case 4: pr6884_abort_struct a; }
98 switch (x) default: L1: L2: case 4: { pr6884_abort_struct a; }
106 struct PR9380_B : public PR9380 {
107 PR9380_B( const PR9380& str );
109 void test_PR9380(const PR9380& aKey) {
110 const PR9380& flatKey = PR9380_B(aKey);
113 // Array of objects with destructors. This is purely a coverage test case.
118 // Test classes wrapped in typedefs. This is purely a coverage test case
119 // for CFGImplictDtor::getDestructorDecl().
120 void test_typedefs() {
121 typedef PR9380 PR9380_Ty;
126 // PR9412 - Handle CFG traversal with null successors.
127 enum PR9412_MatchType { PR9412_Exact };
129 template <PR9412_MatchType type> int PR9412_t() {
135 } // expected-warning {{control reaches end of non-void function}}
138 PR9412_t<PR9412_Exact>(); // expected-note {{in instantiation of function template specialization 'PR9412_t<0>' requested here}}