This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] avoid -Wsuggest-attribute=const for void functions (PR 83559)
- From: Jeff Law <law at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 2 Jan 2018 16:37:53 -0700
- Subject: Re: [PATCH] avoid -Wsuggest-attribute=const for void functions (PR 83559)
- Authentication-results: sourceware.org; auth=none
- References: <e7871939-1e82-1b3a-46eb-0e683ad4fda7@gmail.com>
On 01/01/2018 05:50 PM, Martin Sebor wrote:
> Among the recent -Wattributes enhancements is to diagnose
> declarations of void functions with attribute const or pure.
> Declaring a void function const or pure means that calls to
> the function have no effect and could be (and, with
> optimization, are) eliminated. Thus the attribute on such
> a function would imply that either the function is useless
> or the attribute is (when the function is called inidirectly).
>
> As it happens, however, -Wsuggest-attribute=const suggests
> adding the const attribute to candidate functions that return
> void, thus causing a conflict between the two options.
>
> The attached patch resolves the conflict by avoiding
> -Wsuggest-attribute=const for void functions.
>
> Martin
>
> gcc-83559.diff
>
>
> PR c/83559 - -Wsuggest-attribute=const conflicts with -Wattributes warning about const attribute on function returning void
>
> gcc/ChangeLog:
>
> PR c/83559
> * doc/extend.texi (attribute const): Fix a typo.
> * ipa-pure-const.c ((warn_function_const, warn_function_pure): Avoid
> issuing -Wsuggest-attribute for void functions.
>
> gcc/testsuite/ChangeLog:
>
> PR c/83559
> * gcc.dg/const-2.c: New test.
> * gcc.dg/pure-3.c: New test.
OK
Jeff