This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: "fall-through" errors
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Bruce Korb <bruce dot korb at gmail dot com>
- Cc: GCC List <gcc at gcc dot gnu dot org>
- Date: Sat, 28 Jul 2018 20:48:06 +0200
- Subject: Re: "fall-through" errors
- References: <CAKRnqNJBqv0_=_t4bs3rx-PH=8iLieqvscmjsDbeArOaAfO5Qw@mail.gmail.com> <20180728174439.GQ17988@tucnak> <CAKRnqNK=AWv8+3w82DBzWZ9cw5S9Zyu7w+_71LkCygm6F60OKA@mail.gmail.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Sat, Jul 28, 2018 at 10:56:24AM -0700, Bruce Korb wrote:
> > NOTREACHED means something different, and I don't think we want to add
> > support for this when we already support a way (including a standard way) to
> > mark function pointers noreturn (noreturn attribute, _Noreturn in C).
> > Or you can use -Wimplicit-fallthrough=1 where any kind of comment no matter
> > what you say there will disable the implicit fallthrough warning.
>
> Messing with "noreturn" means messing with autoconf configury and you have no
> idea how much I have always hated that horrific environment. Using the
> "implicit-fallthrough=1" thingy means the same thing, but making sure it is GCC
> and not Clang. That is why using the "obvious" implication that if a function
> does not return, then you won't "accidentally" fall through either. Rather than
> mess with all that, do both: /* FALLTHROUGH */ /* NOTREACHED */
> I think it would be good to reconsider NOTREACHED. Once upon a time,
> I segregated out -Wformat-contains-nul. I could offer again, but it
> would be a long
> time for the round tuit and it would be hard for me.
You don't need to use configure for this, something like:
#ifdef __has_attribute
#if __has_attribute(__noreturn__)
#define NORETURN __attribute__((__noreturn__))
#endif
#endif
#ifndef NORETURN
#define NORETURN
#endif
will do.
Or glibc headers have:
#if defined __GNUC__ && defined __GNUC_MINOR__
# define __GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
# define __GNUC_PREREQ(maj, min) 0
#endif
#if (!defined _Noreturn \
&& (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
&& !__GNUC_PREREQ (4,7))
# if __GNUC_PREREQ (2,8)
# define _Noreturn __attribute__ ((__noreturn__))
# else
# define _Noreturn
# endif
#endif
with
Jakub