[cfe-dev] should -Wimplicit-fallthrough require C++11?

Richard Smith richard at metafoo.co.uk
Fri Nov 9 19:04:13 PST 2012

Hi Ted,

On Fri, Nov 9, 2012 at 5:55 PM, Ted Kremenek <kremenek at apple.com> wrote:
> Hi all,
> In response to numerous internal complaints at Apple from C/Objective-C users, I've gone and disabled -Wimplicit-fallthrough when using straight C (not C++):
>   http://llvm.org/viewvc/llvm-project?view=rev&revision=167655
> The motivation is that the attribute used to decorate a fall-through as explicit is only available when using C++11.  This was particularly frustrating for C users.

I'm not in favor of this change. If people are frustrated that they
can't annotate fallthrough outside C++11, how about we add a
__builtin_fallthrough() which generates no code, and has the same
effect as the [[clang::fallthrough]] attribute? If warning is
considered valuable enough for these users to enable it in C++11 code,
presumably it's valuable enough to be worth making usable outside
C++11 mode.

> I understand that change alone might be contentious, and obviously if there is serious concern that should be discussed.  I'd like to one step further and ask whether or not this warning should even be on when using C++98?  The same argument applies there as well; the attribute to decorate a fall-through as explicit is not available.
> Indeed, I would have gone and restricted this warning to C++11, but apparently there is a test case specifically for the C++98 scenario:
>   test/SemaCXX/switch-implicit-fallthrough-cxx98.cpp
> There was a lot of discussion about this warning when it first went in  Now that the warning is getting real living-on, I was wondering if we can discuss whether this is desired behavior?  It feels somewhat dubious to me to have a warning like this that suggests adding an annotation when no such annotation is available.

[The warning shouldn't suggest adding an annotation outside C++11. If
it does, it's a bug.]

The original intention was that the warning could be used in any
language mode, if you wanted a warning on *all* switch fallthrough,
and that people who didn't want that could just not turn it on. I
guess the complaints you're receiving are for situations where the
warning can't simply be disabled (or not enabled in the first place)?
If we really can't find a better solution for these people than
disabling the warning in languages where we can't annotate
fallthrough, then we should do so consistently and disable it in C++98

More information about the cfe-dev mailing list