| Summary: | Add FALLTHROUGH and -Wimplicit-fallthrough to warn about unannotated implicit fallthroughs in switches | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Joseph Pecoraro <joepeck> | ||||||||
| Component: | Web Template Framework | Assignee: | Nobody <webkit-unassigned> | ||||||||
| Status: | RESOLVED FIXED | ||||||||||
| Severity: | Normal | CC: | andersca, benjamin, cmarcelo, commit-queue, darin, joepeck, sam | ||||||||
| Priority: | P2 | ||||||||||
| Version: | 528+ (Nightly build) | ||||||||||
| Hardware: | Unspecified | ||||||||||
| OS: | Unspecified | ||||||||||
| Attachments: |
|
||||||||||
|
Description
Joseph Pecoraro
2014-01-25 17:23:21 PST
Created attachment 222242 [details]
[PATCH] Proposed Fix - FALLTHROUGH
Any reason not to add this? This adds it to WTF and enables for WTF. I haven't looked at other projects yet (JSC, WebCore, ...)
Attachment 222242 [details] did not pass style-queue:
ERROR: Source/WTF/wtf/Compiler.h:160: Extra space before [ [whitespace/braces] [5]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234: A case label should not be indented, but line up with its switch statement. [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:235: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:236: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256: More than one command on the same line in if [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257: More than one command on the same line in if [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288: A case label should not be indented, but line up with its switch statement. [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:289: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:290: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:291: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:292: More than one command on the same line [whitespace/newline] [4]
Total errors found: 15 in 4 files
If any of these errors are false positives, please file a bug against check-webkit-style.
Created attachment 222243 [details]
[PATCH] Proposed Fix
Now with a ChangeLog.
Attachment 222243 [details] did not pass style-queue:
ERROR: Source/WTF/wtf/Compiler.h:160: Extra space before [ [whitespace/braces] [5]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234: A case label should not be indented, but line up with its switch statement. [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:235: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:236: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256: More than one command on the same line in if [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257: More than one command on the same line in if [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288: A case label should not be indented, but line up with its switch statement. [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:289: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:290: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:291: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:292: More than one command on the same line [whitespace/newline] [4]
Total errors found: 15 in 5 files
If any of these errors are false positives, please file a bug against check-webkit-style.
Comment on attachment 222243 [details] [PATCH] Proposed Fix View in context: https://bugs.webkit.org/attachment.cgi?id=222243&action=review > Source/WTF/wtf/Compiler.h:159 > +#if !defined(FALLTHROUGH) && COMPILER_SUPPORTS(FALLTHROUGH_WARNINGS) > +#if COMPILER(CLANG) Should just be a single #if with another && in it. > Source/WTF/wtf/Compiler.h:165 > +#define FALLTHROUGH do { } while (false) Can this just be defined to nothing? I wouldn’t think it needs to be a statement (see my comments below about semicolons). > Source/WTF/wtf/dtoa/fast-dtoa.cc:257 > + FALLTHROUGH; Does this really require a semicolon after it? That doesn’t seem quite right to me, but maybe that’s how the clang feature works? I don’t think we should keep the "// else fallthrough" comments since we are adding the FALLTHROUGH macros, which say the same thing. There is an advantage to defining the macro without a semicolon. Clang detects if is a macro with the exact text of the fall through extension. So when it emits a warning it suggests using the macro in the build warning:
With: #define FALLTHROUGH [[clang::fallthrough]]
CompileC wtf/dtoa/fast-dtoa.cc
/Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
case 29:
^
/Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: note: insert 'FALLTHROUGH;' to silence this warning
case 29:
^
> FALLTHROUGH;
/Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: note: insert 'break;' to avoid fall-through
case 29:
^
break;
1 error generated.
However, if the macro is not an exact match, e.g. includes a semicolon, the warning doesn't mention the macro at all:
#define FALLTHROUGH [[clang::fallthrough]];
CompileC wtf/dtoa/fast-dtoa.cc
/Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
case 29:
^
/Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: note: insert '[[clang::fallthrough]];' to silence this warning
case 29:
^
> [[clang::fallthrough]];
/Users/pecoraro/Code/webkit/Source/WTF/wtf/dtoa/fast-dtoa.cc:258:13: note: insert 'break;' to avoid fall-through
case 29:
^
break;
1 error generated.
Created attachment 222245 [details]
[PATCH] For Landing
Attachment 222245 [details] did not pass style-queue:
ERROR: Source/WTF/wtf/Compiler.h:159: Extra space before [ [whitespace/braces] [5]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234: A case label should not be indented, but line up with its switch statement. [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:234: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:235: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:236: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:256: More than one command on the same line in if [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:257: More than one command on the same line in if [whitespace/parens] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288: A case label should not be indented, but line up with its switch statement. [whitespace/indent] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:288: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:289: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:290: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:291: More than one command on the same line [whitespace/newline] [4]
ERROR: Source/WTF/wtf/unicode/UTF8.cpp:292: More than one command on the same line [whitespace/newline] [4]
Total errors found: 15 in 5 files
If any of these errors are false positives, please file a bug against check-webkit-style.
Comment on attachment 222245 [details] [PATCH] For Landing Clearing flags on attachment: 222245 Committed r162793: <http://trac.webkit.org/changeset/162793> All reviewed patches have been landed. Closing bug. |