From owner-svn-src-all@FreeBSD.ORG Tue Apr 14 07:11:00 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2176DD40; Tue, 14 Apr 2015 07:11:00 +0000 (UTC) Received: from mail110.syd.optusnet.com.au (mail110.syd.optusnet.com.au [211.29.132.97]) by mx1.freebsd.org (Postfix) with ESMTP id 2E4E6F81; Tue, 14 Apr 2015 07:10:59 +0000 (UTC) Received: from c211-30-166-197.carlnfd1.nsw.optusnet.com.au (c211-30-166-197.carlnfd1.nsw.optusnet.com.au [211.30.166.197]) by mail110.syd.optusnet.com.au (Postfix) with ESMTPS id EEBB27815A9; Tue, 14 Apr 2015 16:46:44 +1000 (AEST) Date: Tue, 14 Apr 2015 16:46:43 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Eitan Adler cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r281517 - head/usr.bin/ipcs In-Reply-To: <201504140452.t3E4qrae040029@svn.freebsd.org> Message-ID: <20150414153545.U838@besplex.bde.org> References: <201504140452.t3E4qrae040029@svn.freebsd.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.1 cv=L/MkHYj8 c=1 sm=1 tr=0 a=KA6XNC2GZCFrdESI5ZmdjQ==:117 a=PO7r1zJSAAAA:8 a=kj9zAlcOel0A:10 a=JzwRw_2MAAAA:8 a=k9hOBJIYsBljULasZeUA:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Apr 2015 07:11:00 -0000 On Tue, 14 Apr 2015, Eitan Adler wrote: > Log: > ipcs: fix builds that use gcc > gcc gets annoyed by duplicate declarations You mean "Fix builds that use a working compiler. Working compilers report redundant declarations when requested to do so by the -Wredundant-decls flag which I recently enabled by raising WARNS to 6." clang apparently silently ignores the request. gcc48 still has the following bugs in -Wredundant-decls: - it redundantly says that redundant declarations are redeclarations. Only a very magic type or variable could redundant if it is only declared once by the program (including in headers included by the program). Perhaps some predefined type or variable is magic enough. But then the warning should be different. E.g., main() and exit() are known to the compiler except in freestanding environments. gcc already has special handling for main(), to allow it to be declared as either "int main(void);" or "int main(int argc, char **argv);", as required to allow the program to use either of these. Declaring one of these in either or a compiler predeclaration would break use of the other one unless the first declaration is magic. I think gcc skips the warning for its builtin predeclaration but wouldn't skip if for a declaration in a header. I think standards don't allow main() to be declared in any standard header since they don't require compilers to have magic to support this. exit() is simpler since it has only 1 correct declaration in hosted environments. It should have a predeclaration in the compiler and another one in . The one in is redundant, but the compiler must not warn about it. The compiler should warn about it for any declaration of it outside of standard headers. The correct practice is to include to get the declaration. That gives at least a doubly-redundant declaration if the application declares it again, and no magic is needed to get the warning. If the application doesn't include , then the warning should change to one about improper practice when certain warnings are enabled. I think gcc only warns about inconsistent uses and the C standard only requires this. So you should be able to non-redundantly declare exit() iff you are careful to not include and use the same declaration as . - it incorrectly says that non-redundant non-redeclarations are redundant redeclarations. C allows building up types by supplying additional information in each step. E.g.: void myfunc(); void myfunc(int); gcc48 still warns that the second declaration is a redundant redeclaration when it is actually a non-redundant non-redeclaration. The first declaration is redundant in some cases (especially when there is nothing between the declarations. Nested incomplete function declarations allow arbitrarily long chains of non-redundant non-redeclarations to build up a single top-level declaration: typedef void ifv(); /* incomplete type for func returning void */ typedef void cfv(int); /* complete type for func returning void */ void myfunc(); void myfunc(ifv *, ifv *); /* parameters incomplete */ void myfunc(cfv *, ifv *); /* complete only first parameter */ void myfunc(ifv *, cfv *); /* complete only first parameter */ /* * All non-redundant so far. The type of myfunc is now complete in * Standard C although not in GNC C, so any further declarations of * all or parts of it are redundant. */ C also allows building up declarations by adding linkage info. This is even more confusing. GNUC also allows building up declarations by adding attribute info one or several but not all attributes at a time. This is less confusing, at least for the 1-at-a-time case. E.g.: void panic(const char *, ...); #ifdef __MUMBLE >= 99 void panic(const char * restrict, ...); /* add C99 feature */ #endif void panic(const char *, ...) __dead2; /* add old GNU feature */ void panic(const char *, ...) __printflike(1, 2); /* newer GNU feature */ void panic(const char *, ...) __nonnull(1); /* even newer GNU feature */ Building up types is very confusing so you should rarely do it, but the above is almost reasonable. Adding the restrict qualifier only for C99 and later is obfuscated in a different way using ifdefs for __restrict. The bugs in "gcc -Wredundant-decls" accidentally detect the style bug of using the building-up-types feature. This should be detected under a different warning. panic(9) is still missing both 'restrict' and __nonnull(1), though it needs __nonull() even more than printf([39]) because a null panicstr is magic (used for recursion detection). Bruce