C++17 feature proposal: [[fallthrough]]

163 views
Skip to first unread message

Roland Bock

unread,
Dec 24, 2021, 11:37:26 AM12/24/21
to cxx
Hi,

The [[fallthrough]] attribute is great for documenting intentional fall-through in a switch statement (as opposed to a forgotten break or return).

It can also be combined with -Wimplicit-fallthrough in clang and gcc to enforce at some point.

Therefore, I nominate [[fallthrough]] from C++17 to be allowed.

Best,

Roland

Peter Kasting

unread,
Dec 24, 2021, 11:40:45 AM12/24/21
to Roland Bock, cxx
We currently use [[clang:fallthrough]], behind the macro FALLTHROUGH, for this purpose (and enforce via the warning you mention).  Presumably, then, this proposal would be to either redefine the macro to just [[fallthrough]] and use it on all compilers, or to also go further and replace use of the macro with direct use of this attribute?

PK

Avi Drissman

unread,
Dec 24, 2021, 11:47:07 AM12/24/21
to Peter Kasting, Roland Bock, cxx
I would support a version of this proposal that called for the removal of the macro FALLTHROUGH and the substitution of [[fallthrough]] everywhere.

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFD%3D%2BwwML-BwGRYfcs11wfKgpP6rshhPXaEthM_H0PiD-w%40mail.gmail.com.

K. Moon

unread,
Dec 24, 2021, 11:49:58 AM12/24/21
to Avi Drissman, Peter Kasting, Roland Bock, cxx
+1 to fewer macros whenever possible.

Roland Bock

unread,
Dec 24, 2021, 12:05:44 PM12/24/21
to K. Moon, Avi Drissman, Peter Kasting, cxx
I was not even aware of the macro (and so weren't others) and it does not seem to be enforced, see this review, for instance :-)

So the proposal would be to 
  • remove the FALLTHROUGH macro and substitute it with [[fallthrough]] everywhere,
  • develop a plan to introduce the -Wimplicit-fallthrough warning at least for our own code.

Lei Zhang

unread,
Dec 24, 2021, 12:09:45 PM12/24/21
to Roland Bock, K. Moon, Avi Drissman, Peter Kasting, cxx
On Fri, Dec 24, 2021 at 9:05 AM 'Roland Bock' via cxx <c...@chromium.org> wrote:
> develop a plan to introduce the -Wimplicit-fallthrough warning at least for our own code.

Already in build/config/compiler/BUILD.gn for chromium_code. Done!

Roland Bock

unread,
Dec 24, 2021, 12:23:35 PM12/24/21
to Lei Zhang, K. Moon, Avi Drissman, Peter Kasting, cxx
Ha, I could have sworn this would warn for something like

switch(x)
  case 0:
  case 1: break;
}

Well, even better :-)

Avi Drissman

unread,
Dec 24, 2021, 12:54:06 PM12/24/21
to Roland Bock, K. Moon, Peter Kasting, cxx
For the proposal of allowing [[fallthrough]] and doing the conversion of FALLTHROUGH, +1.

This should be a pretty straightforward LSC.

Peter Kasting

unread,
Dec 24, 2021, 1:15:59 PM12/24/21
to Avi Drissman, Roland Bock, K. Moon, cxx
On Fri, Dec 24, 2021 at 9:54 AM Avi Drissman <a...@google.com> wrote:
For the proposal of allowing [[fallthrough]] and doing the conversion of FALLTHROUGH, +1.

+1

PK 

Jeremy Roman

unread,
Dec 29, 2021, 11:58:54 AM12/29/21
to Roland Bock, K. Moon, Avi Drissman, Peter Kasting, cxx
I think it's correct for it not to be enforced there. The case of fallthrough between switch cases where there's no code between the case labels is incredibly common and IMO very clear. The problematic case [[fallthrough]] handles is where there is some statement between the two case labels and it's not obvious whether fallthrough was intended or "break;" was forgotten.

i.e. we should write

case 1:
  Foo();
  [[fallthrough]];
case 2:
  Bar();
  break;

but

case 1:
case 2:
  Foo();
  break;

I believe this is what -Wimplicit-fallthrough already demands.

Peter Kasting

unread,
Dec 29, 2021, 1:44:02 PM12/29/21
to Avi Drissman, Roland Bock, K. Moon, cxx
On Fri, Dec 24, 2021 at 9:54 AM Avi Drissman <a...@google.com> wrote:
For the proposal of allowing [[fallthrough]] and doing the conversion of FALLTHROUGH, +1.

This seems pretty non-controversial, so I suggest we consider it approved.  It seems like there are several parts:
(1) Move the [[fallthrough]] attribute to the allowed section of the guide
(2) Write an LSC proposal to search-and-replace FALLTHROUGH with [[fallthrough]]
(3) Do the LSC and eliminate the macro

Roland, what parts of this are you signing up for?  (1), or all three?

PK

Roland Bock

unread,
Dec 29, 2021, 3:15:12 PM12/29/21
to Peter Kasting, Avi Drissman, K. Moon, cxx
I can do (1) for sure.

I am happy to give (2) and (3) a try, too, following https://chromium.googlesource.com/chromium/src/+/HEAD/docs/process/lsc/large_scale_changes.md, I guess.

Roland Bock

unread,
Jan 3, 2022, 9:49:15 AM1/3/22
to cxx, Avi Drissman, K. Moon, Peter Kasting
Happy New Year!

Here is the CL to allow [[fallthrough]].

About the LSC:

Replacing FALLTHROUGH with [[fallthrough]] looks straight forward in most places.

However, I am not sure how to deal with code in third_party/? There seem to be two cases to deal with:
  • pdfium comes with it's own copy of third_party/pdfium/third_party/base/compiler_specific.h
  • everything else is using base/compiler_specific.h, including some generated code for blink
We probably should change the code in third_party/, too? 
Would we inform the respective owners (how)?
What about pdfium? Leave as is, or change it, too?

Thanks!

Roland

Avi Drissman

unread,
Jan 3, 2022, 11:19:46 AM1/3/22
to Roland Bock, cxx, K. Moon, Peter Kasting
PDFium has their own base/ that they do their best to keep in sync; for that, we'd file a bug against them and let them handle it.

For Blink generated code, we would update the generators to no longer use FALLTHROUGH and regenerate the code.

For third_party, you'll need to go case-by-case and figure out how to do it. For some of them, it's in the integration code and you can just change it in the tree. For others, you might need to change it upstream and re-roll the DEPS. I've done this before, so I can give guidance if necessary.

In the past, I've found it useful to do a burndown. Start with the LSC across Chromium and Blink, and let's see what's left.

Lei Zhang

unread,
Jan 3, 2022, 3:30:56 PM1/3/22
to Roland Bock, cxx, Avi Drissman, K. Moon, Peter Kasting
File a bug on https://crbug.com/pdfium/new please.
> --
> You received this message because you are subscribed to the Google Groups "cxx" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
> To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAHq1K7QaEdYBSa3ssfknq0BQMze_ZeFjEKTswMShceby-2zncg%40mail.gmail.com.

Roland Bock

unread,
Jan 4, 2022, 9:19:08 AM1/4/22
to Lei Zhang, cxx, Avi Drissman, K. Moon, Peter Kasting
Whoops! I filled out the LSC template which asked how many CLs  `git cl split` would produce.
Turns out 168  of them (for non-third-party code), which are not live in gerrit.

That was not really intended to happen yet. Fortunately, they are all super simple.

Raphael Kubo Da Costa

unread,
Jan 6, 2022, 4:30:14 AM1/6/22
to cxx, rb...@google.com, cxx
I don't have access to https://crbug.com/1283907 -- hopefully this change is not that controversial :-) Did it get some extra protection labels because it was filed by someone with a google.com email address?

dan...@chromium.org

unread,
Jan 6, 2022, 9:11:10 AM1/6/22
to Raphael Kubo Da Costa, cxx, rb...@google.com

Roland Bock

unread,
Jan 13, 2022, 8:47:37 AM1/13/22
to danakj, Raphael Kubo Da Costa, cxx
Just for completeness:

The FALLTHROUGH macro is now gone.

Thanks to everyone who helped with the various CLs on the way :-)

Cheers,

Roland
Reply all
Reply to author
Forward
0 new messages