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. 5void pr6884_abort() __attribute__((noreturn)); 6 7struct pr6884_abort_struct { 8 pr6884_abort_struct() {} 9 ~pr6884_abort_struct() __attribute__((noreturn)) { pr6884_abort(); } 10}; 11 12struct 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. 17namespace abort_struct_complex_cfgs { 18 int basic(int x) { 19 switch (x) { default: pr6884_abort(); } 20 } 21 int f1(int x) { 22 switch (x) default: pr6884_abort_struct(); 23 } 24 int f2(int x) { 25 switch (x) { default: pr6884_abort_struct(); } 26 } 27 int f2_positive(int x) { 28 switch (x) { default: ; } 29 } // expected-warning {{control reaches end of non-void function}} 30 int f3(int x) { 31 switch (x) { default: { pr6884_abort_struct(); } } 32 } 33 int f4(int x) { 34 switch (x) default: L1: L2: case 4: pr6884_abort_struct(); 35 } 36 int f5(int x) { 37 switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); } 38 } 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. 45 int g1(int x) { 46 other o; 47 switch (x) default: pr6884_abort_struct(); 48 } 49 int g2(int x) { 50 other o; 51 switch (x) { default: pr6884_abort_struct(); } 52 } 53 int g2_positive(int x) { 54 other o; 55 switch (x) { default: ; } 56 } // expected-warning {{control reaches end of non-void function}} 57 int g3(int x) { 58 other o; 59 switch (x) { default: { pr6884_abort_struct(); } } 60 } 61 int g4(int x) { 62 other o; 63 switch (x) default: L1: L2: case 4: pr6884_abort_struct(); 64 } 65 int g5(int x) { 66 other o; 67 switch (x) default: L1: { L2: case 4: pr6884_abort_struct(); } 68 } 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. 76 int h1(int x) { 77 other o; 78 switch (x) default: pr6884_abort_struct a; 79 } 80 int h2(int x) { 81 other o; 82 switch (x) { default: pr6884_abort_struct a; } 83 } 84 int h3(int x) { 85 other o; 86 switch (x) { default: { pr6884_abort_struct a; } } 87 } 88 int h4(int x) { 89 other o; 90 switch (x) default: L1: L2: case 4: pr6884_abort_struct a; 91 } 92 int h5(int x) { 93 other o; 94 switch (x) default: L1: { L2: case 4: pr6884_abort_struct a; } 95 } 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 103struct PR9380 { 104 ~PR9380(); 105}; 106struct PR9380_B : public PR9380 { 107 PR9380_B( const PR9380& str ); 108}; 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. 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(). 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. 127enum PR9412_MatchType { PR9412_Exact }; 128 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 137void PR9412_f() { 138 PR9412_t<PR9412_Exact>(); // expected-note {{in instantiation of function template specialization 'PR9412_t<0>' requested here}} 139} 140 141