From owner-svn-src-head@freebsd.org Wed May 3 21:35:07 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8840FD5B673; Wed, 3 May 2017 21:35:07 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail105.syd.optusnet.com.au (mail105.syd.optusnet.com.au [211.29.132.249]) by mx1.freebsd.org (Postfix) with ESMTP id 3640E1893; Wed, 3 May 2017 21:35:07 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from besplex.bde.org (c122-106-153-191.carlnfd1.nsw.optusnet.com.au [122.106.153.191]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id 180121047791; Thu, 4 May 2017 07:34:59 +1000 (AEST) Date: Thu, 4 May 2017 07:34:58 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Alan Somers cc: Bruce Evans , Eric van Gyzen , Warner Losh , Ngie Cooper , "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Subject: Re: svn commit: r317755 - head/sbin/ifconfig In-Reply-To: Message-ID: <20170504071824.H1678@besplex.bde.org> References: <201705031721.v43HL2vS071819@repo.freebsd.org> <8EA7A2E9-A429-4DC2-85CE-1B5AAEDF86FD@gmail.com> <20170504062448.U1383@besplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.2 cv=AYLBJzfG c=1 sm=1 tr=0 a=Tj3pCpwHnMupdyZSltBt7Q==:117 a=Tj3pCpwHnMupdyZSltBt7Q==:17 a=kj9zAlcOel0A:10 a=PO7r1zJSAAAA:8 a=7Qk2ozbKAAAA:8 a=6I5d2MoRAAAA:8 a=pGLkceISAAAA:8 a=GA-xqR6bnEjevdNG3BwA:9 a=CjuIK1q_8ugA:10 a=1lyxoWkJIXJV6VJUPhuM:22 a=IjZwj45LgO3ly-622nXo:22 a=6kGIvZw6iX1k4Y-7sg4_:22 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 May 2017 21:35:07 -0000 On Wed, 3 May 2017, Alan Somers wrote: > On Wed, May 3, 2017 at 2:51 PM, Bruce Evans wrote: >> 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 wrote: >>>>> >>>>> On Wed, May 3, 2017 at 1:32 PM, Alan Somers wrote: >>>>>> >>>>>> On Wed, May 3, 2017 at 12:16 PM, Ngie Cooper >>>>>> wrote: >>>>>>> >>>>>>> >>>>>>>> On May 3, 2017, at 10:21, Alan Somers 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 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 >> _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 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 . I think its >> keyword must be spelled [[noreturn]]. This spelling is completely >> incompatibly with C. > > Why do you say that cdefs.h should be compatible with gcc-1? gcc-2 Because that is what it is for. It should be compatible with any C compiler, not just gcc or Standard C ones, but since it grew up with gcc it doesn't have much support for others. It still pretends to supports gcc-1 with pre-Standard C (__P(()), etc.) and even compilers that don't have pre-Standard volatile (pure K&R1 for that and not K&R with gcc-1 extensions), and lint. Some of this still works. > was released more than 25 years ago. gcc-1 isn't the default compiler > for any architecture and isn't available in ports. If anybody can > find a copy of gcc-1, I doubt that much of our codebase would compile. > It sounds to me that the best practice would be to place both __dead2 > and _Noreturn before the function name. Unportable code can do that. Of course, it is unportable to include at all. Usign __dead2 gives undefined behaviour in general. Even if you include , it might not be the FreeBSD one. Using _Noreturn gives undefined behaviour before C11. Bruce