Recent work on -Wunreachable-code has focused on suppressing uninteresting unreachable code that center around "configuration values", but there are still some set of cases that are sometimes interesting or uninteresting depending on the codebase. For example, a dead "break" statement may not be interesting for a particular codebase, potentially because it is auto-generated or simply because code is written defensively. To address these workflow differences, -Wunreachable-code is now broken into several diagnostic groups: -Wunreachable-code: intended to be a reasonable "default" for most users. and then other groups that turn on more aggressive checking: -Wunreachable-code-break: warn about dead break statements -Wunreachable-code-trivial-return: warn about dead return statements that return "trivial" values (e.g., return 0). Other return statements that return non-trivial values are still reported under -Wunreachable-code (this is an area subject to more refinement). -Wunreachable-code-aggressive: supergroup that enables all these groups. The goal is to eventually make -Wunreachable-code good enough to either be in -Wall or on-by-default, thus finessing these warnings into different groups helps achieve maximum signal for more users. TODO: the tests need to be updated to reflect this extra control via diagnostic flags. llvm-svn: 203994
71 lines
1.4 KiB
C++
71 lines
1.4 KiB
C++
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code-aggressive -fblocks -verify %s
|
|
|
|
int j;
|
|
int bar();
|
|
int test1() {
|
|
for (int i = 0;
|
|
i != 10;
|
|
++i) { // expected-warning {{will never be executed}}
|
|
if (j == 23) // missing {}'s
|
|
bar();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
return 1; // expected-warning {{will never be executed}}
|
|
}
|
|
|
|
int test1_B() {
|
|
for (int i = 0;
|
|
i != 10;
|
|
++i) { // expected-warning {{will never be executed}}
|
|
if (j == 23) // missing {}'s
|
|
bar();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
return bar(); // expected-warning {{will never be executed}}
|
|
}
|
|
|
|
void test2(int i) {
|
|
switch (i) {
|
|
case 0:
|
|
break;
|
|
bar(); // expected-warning {{will never be executed}}
|
|
case 2:
|
|
switch (i) {
|
|
default:
|
|
a: goto a;
|
|
}
|
|
bar(); // expected-warning {{will never be executed}}
|
|
}
|
|
b: goto b;
|
|
bar(); // expected-warning {{will never be executed}}
|
|
}
|
|
|
|
void test3() {
|
|
^{ return;
|
|
bar(); // expected-warning {{will never be executed}}
|
|
}();
|
|
while (++j) {
|
|
continue;
|
|
bar(); // expected-warning {{will never be executed}}
|
|
}
|
|
}
|
|
|
|
// PR 6130 - Don't warn about bogus unreachable code with throw's and
|
|
// temporary objects.
|
|
class PR6130 {
|
|
public:
|
|
PR6130();
|
|
~PR6130();
|
|
};
|
|
|
|
int pr6130(unsigned i) {
|
|
switch(i) {
|
|
case 0: return 1;
|
|
case 1: return 2;
|
|
default:
|
|
throw PR6130(); // no-warning
|
|
}
|
|
}
|