https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81392
Bug ID: 81392 Summary: Improve diagnostics for [[fallthrough]] attribute that is missing a semicolon Product: gcc Version: 8.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: cody at codygray dot com Target Milestone: --- The C++1z/C++17 draft standard introduces a [[fallthrough]] attribute to explicitly document that fall-through behavior is intended in a switch-case block. This works in conjunction with G++'s -Wimplicit-fallthrough option, which gives a warning about potentially unintended fall-through behaviors. The [[fallthrough]] attribute is required to be applied to an empty statement (see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0188r1.pdf), and therefore requires a terminating semicolon. However, forgetting that semicolon is a common error. With the following code: #include <iostream> int main() { switch (0) { case 0: std::cout << "a\n"; [[fallthrough]] case 1: std::cout << "b\n"; break; } } G++ (7.1 and the current trunk of 8.0) issues the following warning: warning: this statement may fall through [-Wimplicit-fallthrough=] std::cout << "a\n"; ~~~~~~~~~~^~~~~~~~ This is less helpful than it could be. The current Clang trunk provides a substantially more helpful error message in this case: error: fallthrough attribute is only allowed on empty statements [[fallthrough]] ^ note: did you forget ';'? [[fallthrough]] ^ ; It would be nice to have something similar in G++.