Closed Bug 1215411 (MOZ_FALLTHROUGH) Opened 9 years ago Closed 9 years ago

Define MOZ_FALLTHROUGH annotation to suppress clang's -Wimplicit-fallthrough warnings

Categories

(Core :: MFBT, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla44
Tracking Status
firefox44 --- fixed

People

(Reporter: cpeterson, Assigned: cpeterson)

References

Details

Attachments

(1 file)

Attached patch MOZ_FALLTHROUGH.patch — — Splinter Review
clang's optional -Wimplicit-fallthrough compiler warning warns about switch
cases that fall through without a break or return statement. MOZ_FALLTHROUGH is an annotation to suppress these warnings. MOZ_FALLTHROUGH is only needed on cases that have code.

I'd like to start fixing the 670 -Wimplicit-fallthrough warnings in mozilla-central. I have local patches to annotate about 200 cases so far and I have found at least 4 real bugs. :)

  switch (foo) {
    case 1: // These cases have no code. No fallthrough annotations are needed.
    case 2:
    case 3:
      foo = 4; // This case has code, so a fallthrough annotation is needed:
      MOZ_FALLTHROUGH;
    default:
      return foo;
  }

clang's fallthrough annotation is only available starting in C++11 because it uses C++11 annotation syntax. MSVC's __fallthrough annotations are checked by MSVC /analyze (Code Analysis), though I have not tested it. gcc does not have a similar warning or annotation.
Attachment #8674690 - Flags: review?(Ms2ger)
Comment on attachment 8674690 [details] [diff] [review]
MOZ_FALLTHROUGH.patch

Review of attachment 8674690 [details] [diff] [review]:
-----------------------------------------------------------------

Seems neat.
Attachment #8674690 - Flags: review?(botond)
Attachment #8674690 - Flags: review?(Ms2ger)
Attachment #8674690 - Flags: feedback+
Attachment #8674690 - Flags: review?(botond) → review-
Comment on attachment 8674690 [details] [diff] [review]
MOZ_FALLTHROUGH.patch

Sorry, I meant to r+!
Attachment #8674690 - Flags: review- → review+
Thanks!
Keywords: checkin-needed
Alias: MOZ_FALLTHROUGH
Keywords: checkin-needed
Blocks: 1215892
Blocks: 1215894
Blocks: 1215898
Blocks: 1215902
https://hg.mozilla.org/mozilla-central/rev/b63d88406a53
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla44
Blocks: 1216414
Blocks: 1216416
Blocks: 1217726
Blocks: 1219139
Blocks: 1220035
Blocks: 1223265
Blocks: 1235233
Blocks: 1235234
Blocks: 1235235
Blocks: 1235237
Blocks: 1235238
Blocks: 1235297
Blocks: 1235298
Blocks: 1235306
Blocks: 1235308
Blocks: 1236321
Blocks: 1236324
Blocks: 1236323
Blocks: 1236322
Blocks: 1236325
Blocks: 1236389
Blocks: 1236393
Blocks: 1236413
Blocks: 1240260
Blocks: 1240262
Blocks: 1240263
Blocks: 1240264
Blocks: 1240265
Blocks: 1241549
Blocks: 1242120
Blocks: 1242135
Blocks: 1243647
Blocks: 1247531
Blocks: 1247532
Blocks: 1247533
Blocks: 1251887
Blocks: 1253170
Blocks: 1253753
Depends on: 1355692
Depends on: 1387388
Depends on: 1387569
Depends on: fallthrough
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: