File tree Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Expand file tree Collapse file tree 2 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,26 @@ code bases.
8181 ``-fno-strict-overflow `` to opt-in to a language dialect where signed integer
8282 and pointer overflow are well-defined.
8383
84+ - ``-Wreturn-type `` now diagnoses missing returns when the default branch of a
85+ switch statement's default branch misses a return, even if the switch covers
86+ all enum values.
87+
88+ This was previously ok and is now warned about:
89+
90+ .. code-block :: c++
91+
92+ enum E { a, b };
93+
94+ int foo(E e) {
95+ switch(e) {
96+ case a:
97+ return 20;
98+ case b:
99+ return 30;
100+ }
101+ // warning: non-void function does not return a value in all control paths
102+ }
103+
84104C/C++ Language Potentially Breaking Changes
85105-------------------------------------------
86106
Original file line number Diff line number Diff line change @@ -170,16 +170,18 @@ void test_nested_switch() {
170170 }
171171}
172172
173- // Test that a warning is not emitted if the code is unreachable.
173+ // Test that if all the values of an enum covered, that the 'default' branch
174+ // is reachable.
174175enum Values { A, B, C, D };
175176void test_all_enums_covered (enum Values v) {
176- int x[2 ];
177- if (v == A) {
178- return ;
179- } else {
180- return ;
177+ int x[2 ]; // expected-note {{array 'x' declared here}}
178+ switch (v) {
179+ case A: return ;
180+ case B: return ;
181+ case C: return ;
182+ case D: return ;
181183 }
182- x[2 ] = 0 ; // no -warning
184+ x[2 ] = 0 ; // expected -warning {{array index 2 is past the end of the array (that has type 'int[2]')}}
183185}
184186
185187namespace tailpad {
You can’t perform that action at this time.
0 commit comments