File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -108,11 +108,15 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) {
108
108
bool HasFakeEdge = false ;
109
109
bool HasPlainEdge = false ;
110
110
bool HasAbnormalEdge = false ;
111
- for (CFGBlock::pred_iterator I=cfg->getExit ().pred_begin (),
112
- E = cfg->getExit ().pred_end ();
113
- I != E;
114
- ++I) {
115
- CFGBlock& B = **I;
111
+
112
+ // Ignore default cases that aren't likely to be reachable because all
113
+ // enums in a switch(X) have explicit case statements.
114
+ CFGBlock::FilterOptions FO;
115
+ FO.IgnoreDefaultsWithCoveredEnums = 1 ;
116
+
117
+ for (CFGBlock::filtered_pred_iterator
118
+ I = cfg->getExit ().filtered_pred_start_end (FO); I.hasMore (); ++I) {
119
+ const CFGBlock& B = **I;
116
120
if (!live[B.getBlockID ()])
117
121
continue ;
118
122
if (B.size () == 0 ) {
Original file line number Diff line number Diff line change @@ -242,3 +242,16 @@ static inline int si_forward() {} // expected-warning{{control reaches end of no
242
242
// Test warnings on ignored qualifiers on return types.
243
243
const int ignored_c_quals (); // expected-warning{{'const' type qualifier on return type has no effect}}
244
244
const volatile int ignored_cv_quals (); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
245
+
246
+ // Test that for switch(enum) that if the switch statement covers all the cases
247
+ // that we don't consider that for -Wreturn-type.
248
+ enum Cases { C1 , C2 , C3 , C4 };
249
+ int test_enum_cases (enum Cases C ) {
250
+ switch (C ) {
251
+ case C1 : return 1 ;
252
+ case C2 : return 2 ;
253
+ case C4 : return 3 ;
254
+ case C3 : return 4 ;
255
+ }
256
+ } // no-warning
257
+
You can’t perform that action at this time.
0 commit comments