[Bug c++/107571] New: Missing fallthrough attribute diagnostics
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Nov 8 14:49:02 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107571
Bug ID: 107571
Summary: Missing fallthrough attribute diagnostics
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jakub at gcc dot gnu.org
Target Milestone: ---
On:
void
foo (int n)
{
void g(), h(), i();
switch (n)
{
case 1:
case 2:
g();
[[fallthrough]];
case 3: // warning on fallthrough discouraged
do {
[[fallthrough]]; // error: next statement is not part of the same
substatement execution
} while (false);
case 6:
do {
[[fallthrough]]; // error: next statement is not part of the same
substatement execution
} while (n--);
case 7:
while (false) {
[[fallthrough]]; // error: next statement is not part of the same
substatement execution
}
case 5:
h();
case 4: // implementation may warn on fallthrough
i();
[[fallthrough]]; // error
}
}
mentioned in https://isocpp.org/files/papers/D2552R1.pdf we don't diagnose
misplaced [[fallthrough]] in 2 spots.
The original dump shows:
switch (n)
{
case 1:;
case 2:;
<<cleanup_point <<< Unknown tree: expr_stmt
g () >>>>>;
<<cleanup_point <<< Unknown tree: expr_stmt
.FALLTHROUGH () >>>>>;
case 3:;
<<cleanup_point <<< Unknown tree: expr_stmt
.FALLTHROUGH () >>>>>;
case 6:;
<D.2778>:;
<<cleanup_point <<< Unknown tree: expr_stmt
.FALLTHROUGH () >>>>>;
if (<<cleanup_point n-- != 0>>) goto <D.2778>; else goto <D.2776>;
<D.2776>:;
case 7:;
goto <D.2779>;
<<cleanup_point <<< Unknown tree: expr_stmt
.FALLTHROUGH () >>>>>;
<D.2779>:;
case 5:;
<<cleanup_point <<< Unknown tree: expr_stmt
h () >>>>>;
case 4:;
<<cleanup_point <<< Unknown tree: expr_stmt
i () >>>>>;
<<cleanup_point <<< Unknown tree: expr_stmt
.FALLTHROUGH () >>>>>;
}
so the reason we don't warn in the do { ... } while (false); case is that it
disappears probably during
genericize_c_loop and the while (false) case because the genericization in that
case makes the loop body followed by artificial label.
More information about the Gcc-bugs
mailing list