Date: Thu, 4 May 2017 06:51:20 +1000 (EST) From: Bruce Evans <brde@optusnet.com.au> To: Eric van Gyzen <eric@vangyzen.net> Cc: Alan Somers <asomers@freebsd.org>, Warner Losh <imp@bsdimp.com>, Ngie Cooper <yaneurabeya@gmail.com>, "src-committers@freebsd.org" <src-committers@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org> Subject: Re: svn commit: r317755 - head/sbin/ifconfig Message-ID: <20170504062448.U1383@besplex.bde.org> In-Reply-To: <e93b38b5-6d1b-b463-ab50-b3f9ac2c4a17@vangyzen.net> References: <201705031721.v43HL2vS071819@repo.freebsd.org> <8EA7A2E9-A429-4DC2-85CE-1B5AAEDF86FD@gmail.com> <CAOtMX2hbiXAna_UxMonf1Drqx3PkzW2%2BToezai%2BQ32VYq_DXSg@mail.gmail.com> <CANCZdfpgUif9STteK=W3Pr0D9UqkPqU9edZqXLfLyoD5d=UPag@mail.gmail.com> <CAOtMX2iC9dqBmWHGODA%2BMg8caxeKP%2BtEGzGdXD48QaB0a9U5UQ@mail.gmail.com> <e93b38b5-6d1b-b463-ab50-b3f9ac2c4a17@vangyzen.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 3 May 2017, Eric van Gyzen wrote: > On 05/03/2017 14:38, Alan Somers wrote: >> On Wed, May 3, 2017 at 1:34 PM, Warner Losh <imp@bsdimp.com> wrote: >>> On Wed, May 3, 2017 at 1:32 PM, Alan Somers <asomers@freebsd.org> wrote: >>>> On Wed, May 3, 2017 at 12:16 PM, Ngie Cooper <yaneurabeya@gmail.com> wrote: >>>>> >>>>>> On May 3, 2017, at 10:21, Alan Somers <asomers@FreeBSD.org> wrote: >>>>>> >>>>>> Author: asomers >>>>>> Date: Wed May 3 17:21:01 2017 >>>>>> New Revision: 317755 >>>>>> URL: https://svnweb.freebsd.org/changeset/base/317755 >>>>>> >>>>>> Log: >>>>>> Various Coverity fixes in ifconfig(8) >>>>> >>>>> ... >>>>> >>>>>> * Mark usage() as _Noreturn (1305806, 1305750) >>>>> >>>>> ... >>>>> >>>>>> -static void usage(void); >>>>>> +static void usage(void) _Noreturn; >>>>> >>>>> Hi Alan, >>>>> Please use __dead2 instead to be consistent with legacy use of similar gcc attributes. >>>>> Thanks, >>>>> -Ngie >>>> >>>> Why not use _Noreturn? It's standardized by C11, so tools understand >>>> it better than __dead2. >>> >>> Tools that can't understand #define __dead2 _Noreturn aren't worth supporting. >> Some tools don't expand preprocessor macros. Like my editor, for >> example, which highlights _Noreturn as a keyword but not __dead2. > > Please use _Noreturn, because it's standard. sys/cdefs.h already > defines it appropriately for C < C11. _Noreturn is far too hard to use. The above use of it is a syntax error: pts/12:bde@freefall:~/u3> cat z.c void foo(void) _Noreturn; _Noreturn void foo(void); pts/12:bde@freefall:~/u3> cc -std=c11 z.c z.c:1:16: error: '_Noreturn' keyword must precede function declarator void foo(void) _Noreturn; ^~~~~~~~~ _Noreturn 1 error generated. sys/cdefs.h defines might define it appropropriately for C < C11, but it defines it as __dead2 for all C, so prevents the C11 _Noreturn keyword being used. This normally breaks detection of the syntax error. Normally <sys/cdefs.h> is included first, so you __dead2 obfuscated by spelling it _Noreturn instead of C11 _Noreturn. Defining _Noreturn as __dead2 is wrong because it gives the opposite syntax error. __dead2 can now be placed anywhere, but everything in sys/cdefs.h is supposed to be portable back to gcc-1. __dead2 must be placed after the function for gcc-2.0, since __attribute__(()) had more restrictions then. So if you write: #include <sys/cdefs.h> _Noreturn void foo(void); to satisfy the C11 syntax, then you get a syntax error for old gcc (> 1). This is just the start of the complications for soft-coded C11'isms. C11 also has noreturn. You have to include <stdnoreturn.h> to get that. But you actiually get the _Noreturn macro which expands to __dead2. There are further complications for C++11. sys/cdefs.h does have a correct-looking ifdef for C+11. This gives the [[noreturn]] keyward instead of __dead2. C11 doesn't have <stdnoreturn.h>. I think its keyword must be spelled [[noreturn]]. This spelling is completely incompatibly with C. Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170504062448.U1383>