1 // RUN: %clang_cc1 %s -fsyntax-only -verify -Wreturn-type -Wmissing-noreturn -Wno-unreachable-code -Wno-covered-switch-default 2 // RUN: %clang_cc1 %s -fsyntax-only -std=c++11 -verify -Wreturn-type -Wmissing-noreturn -Wno-unreachable-code -Wno-covered-switch-default 3 4 // A destructor may be marked noreturn and should still influence the CFG. 5 void pr6884_abort() __attribute__((noreturn)); 6 7 struct pr6884_abort_struct { pr6884_abort_structpr6884_abort_struct8 pr6884_abort_struct() {} ~pr6884_abort_structpr6884_abort_struct9 ~pr6884_abort_struct() __attribute__((noreturn)) { pr6884_abort(); } 10 }; 11 ~otherother12struct other { ~other() {} }; 13 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 { basic(int x)18 int basic(int x) { 19 switch (x) { default: pr6884_abort(); } 20 } f1(int x)21 int f1(int x) { 22 switch (x) default: pr6884_abort_struct(); 23 } f2(int x)24 int f2(int x) { 25 switch (x) { default: pr6884_abort_struct(); } 26 } f2_positive(int x)27 int f2_positive(int x) { 28 switch (x) { default: ; } 29 } // expected-warning {{control reaches end of non-void function}} f3(int x)30 int f3(int x) { 31 switch (x) { default: { pr6884_abort_struct(); } } 32 } f4(int x)33 int f4(int x) { 34 switch (x) default: L1: L2: case 4: pr6884_abort_struct(); 35 } f5(int x)36 int f5(int x) { 37 switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); } 38 } f6(int x)39 int f6(int x) { 40 switch (x) default: L1: L2: case 4: { pr6884_abort_struct(); } 41 } 42 43 // Test that these constructs work even when extraneous blocks are created 44 // before and after the switch due to implicit destructors. g1(int x)45 int g1(int x) { 46 other o; 47 switch (x) default: pr6884_abort_struct(); 48 } g2(int x)49 int g2(int x) { 50 other o; 51 switch (x) { default: pr6884_abort_struct(); } 52 } g2_positive(int x)53 int g2_positive(int x) { 54 other o; 55 switch (x) { default: ; } 56 } // expected-warning {{control reaches end of non-void function}} g3(int x)57 int g3(int x) { 58 other o; 59 switch (x) { default: { pr6884_abort_struct(); } } 60 } g4(int x)61 int g4(int x) { 62 other o; 63 switch (x) default: L1: L2: case 4: pr6884_abort_struct(); 64 } g5(int x)65 int g5(int x) { 66 other o; 67 switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); } 68 } g6(int x)69 int g6(int x) { 70 other o; 71 switch (x) default: L1: L2: case 4: { pr6884_abort_struct(); } 72 } 73 74 // Test that these constructs work even with variables carrying the no-return 75 // destructor instead of temporaries. h1(int x)76 int h1(int x) { 77 other o; 78 switch (x) default: pr6884_abort_struct a; 79 } h2(int x)80 int h2(int x) { 81 other o; 82 switch (x) { default: pr6884_abort_struct a; } 83 } h3(int x)84 int h3(int x) { 85 other o; 86 switch (x) { default: { pr6884_abort_struct a; } } 87 } h4(int x)88 int h4(int x) { 89 other o; 90 switch (x) default: L1: L2: case 4: pr6884_abort_struct a; 91 } h5(int x)92 int h5(int x) { 93 other o; 94 switch (x) default: L1: { L2: case 4: pr6884_abort_struct a; } 95 } h6(int x)96 int h6(int x) { 97 other o; 98 switch (x) default: L1: L2: case 4: { pr6884_abort_struct a; } 99 } 100 } 101 102 // PR9380 103 struct PR9380 { 104 ~PR9380(); 105 }; 106 struct PR9380_B : public PR9380 { 107 PR9380_B( const PR9380& str ); 108 }; test_PR9380(const PR9380 & aKey)109void test_PR9380(const PR9380& aKey) { 110 const PR9380& flatKey = PR9380_B(aKey); 111 } 112 113 // Array of objects with destructors. This is purely a coverage test case. test_array()114void test_array() { 115 PR9380 a[2]; 116 } 117 118 // Test classes wrapped in typedefs. This is purely a coverage test case 119 // for CFGImplictDtor::getDestructorDecl(). test_typedefs()120void test_typedefs() { 121 typedef PR9380 PR9380_Ty; 122 PR9380_Ty test; 123 PR9380_Ty test2[20]; 124 } 125 126 // PR9412 - Handle CFG traversal with null successors. 127 enum PR9412_MatchType { PR9412_Exact }; 128 PR9412_t()129template <PR9412_MatchType type> int PR9412_t() { 130 switch (type) { 131 case PR9412_Exact: 132 default: 133 break; 134 } 135 } // expected-warning {{control reaches end of non-void function}} 136 PR9412_f()137void PR9412_f() { 138 PR9412_t<PR9412_Exact>(); // expected-note {{in instantiation of function template specialization 'PR9412_t<0>' requested here}} 139 } 140 141