Skip to content

Commit 4858f58

Browse files
committed
Update a test and add a note to the release notes
1 parent 05c6f75 commit 4858f58

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
84104
C/C++ Language Potentially Breaking Changes
85105
-------------------------------------------
86106

clang/test/SemaCXX/array-bounds.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff 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.
174175
enum Values { A, B, C, D };
175176
void 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

185187
namespace tailpad {

0 commit comments

Comments
 (0)