Message ID | 294fd87f-05c2-d804-87cf-7b28563e931e@inango-systems.com |
---|---|
State | New |
Headers | show |
Series | Add option to control warnings added through attribure "warning" | expand |
On 10/12/2018 04:14 AM, Nikolai Merinov wrote: > Hello, > > In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I > suggested patch to have ability to control behavior of > "__attribute__((warning))" in case when option "-Werror" enabled. Usage > example: > >> #include <string.h> >> int a() __attribute__((warning("Warning: `a' was used"))); >> int a() { return 1; } >> int main () { return a(); } > >> $ gcc -Werror test.c >> test.c: In function ‘main’: >> test.c:4:22: error: call to ‘a’ declared with attribute warning: >> Warning: `a' was used [-Werror] >> int main () { return a(); } >> ^ >> cc1: all warnings being treated as errors >> $ gcc -Werror -Wno-error=warning-attribute test.c >> test.c: In function ‘main’: >> test.c:4:22: warning: call to ‘a’ declared with attribute warning: >> Warning: `a' was used >> int main () { return a(); } >> ^ > Can you provide any feedback on suggested changes? It seems like a useful feature and in line with the philosophy that distinct warnings should be controlled by their own options. I would only suggest to consider changing the name to -Wattribute-warning, because it applies specifically to that attribute (as opposed to warnings about attributes in general). There are many attributes in GCC and diagnosing problems that are unique to each, under the same -Wattributes option, is becoming too coarse and overly limiting. To make it more flexible, I expect new options will need to be introduced, such as -Wattribute-alias (to control aspects of the alias attribute and others related to it), or -Wattribute-const (to control diagnostics about functions declared with attribute const that violate the attribute's constraints). An alternative might be to introduce a single -Wattribute= <attribute-list> option where the <attribute-list> gives the names of all the distinct attributes whose unique diagnostics one might need to control. Martin
Hi Martin, On 10/12/18 9:58 PM, Martin Sebor wrote: > On 10/12/2018 04:14 AM, Nikolai Merinov wrote: >> Hello, >> >> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I >> suggested patch to have ability to control behavior of >> "__attribute__((warning))" in case when option "-Werror" enabled. Usage >> example: >> >>> #include <string.h> >>> int a() __attribute__((warning("Warning: `a' was used"))); >>> int a() { return 1; } >>> int main () { return a(); } >> >>> $ gcc -Werror test.c >>> test.c: In function ‘main’: >>> test.c:4:22: error: call to ‘a’ declared with attribute warning: >>> Warning: `a' was used [-Werror] >>> int main () { return a(); } >>> ^ >>> cc1: all warnings being treated as errors >>> $ gcc -Werror -Wno-error=warning-attribute test.c >>> test.c: In function ‘main’: >>> test.c:4:22: warning: call to ‘a’ declared with attribute warning: >>> Warning: `a' was used >>> int main () { return a(); } >>> ^ >> Can you provide any feedback on suggested changes? > > It seems like a useful feature and in line with the philosophy > that distinct warnings should be controlled by their own options. > > I would only suggest to consider changing the name to > -Wattribute-warning, because it applies specifically to that > attribute (as opposed to warnings about attributes in general). > > There are many attributes in GCC and diagnosing problems that > are unique to each, under the same -Wattributes option, is > becoming too coarse and overly limiting. To make it more > flexible, I expect new options will need to be introduced, > such as -Wattribute-alias (to control aspects of the alias > attribute and others related to it), or -Wattribute-const > (to control diagnostics about functions declared with > attribute const that violate the attribute's constraints). > > An alternative might be to introduce a single -Wattribute= > <attribute-list> option where the <attribute-list> gives > the names of all the distinct attributes whose unique > diagnostics one might need to control. > > Martin Currently there is several styles already in use: -Wattribute-alias where "attribute" word used as prefix for name of attribute, -Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of attribute passed as possible argument, -Wmissing-format-attribute where "attribute" word used as suffix, -Wdeprecated-declarations where "attribute" word not used at all even if this warning option was created especially for "deprecated" attribute. I changed name to "-Wattribute-warning" as you suggested, but unifying style for all attribute related warning looks like separate activity. Please check new patch in attachments. Updated changelog: gcc/Changelog 2018-10-14 Nikolai Merinov <n.merinov@inango-systems.com> * gcc/common.opt: Add -Wattribute-warning. * gcc/doc/invoke.texi: Add documentation for -Wno-attribute-warning. * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test. * gcc/expr.c (expand_expr_real_1): Add new attribute to warning_at call to allow user configure behavior of "warning" attribute
On 10/15/2018 01:55 AM, Nikolai Merinov wrote: > Hi Martin, > > On 10/12/18 9:58 PM, Martin Sebor wrote: >> On 10/12/2018 04:14 AM, Nikolai Merinov wrote: >>> Hello, >>> >>> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I >>> suggested patch to have ability to control behavior of >>> "__attribute__((warning))" in case when option "-Werror" enabled. Usage >>> example: >>> >>>> #include <string.h> >>>> int a() __attribute__((warning("Warning: `a' was used"))); >>>> int a() { return 1; } >>>> int main () { return a(); } >>> >>>> $ gcc -Werror test.c >>>> test.c: In function ‘main’: >>>> test.c:4:22: error: call to ‘a’ declared with attribute warning: >>>> Warning: `a' was used [-Werror] >>>> int main () { return a(); } >>>> ^ >>>> cc1: all warnings being treated as errors >>>> $ gcc -Werror -Wno-error=warning-attribute test.c >>>> test.c: In function ‘main’: >>>> test.c:4:22: warning: call to ‘a’ declared with attribute warning: >>>> Warning: `a' was used >>>> int main () { return a(); } >>>> ^ >>> Can you provide any feedback on suggested changes? >> >> It seems like a useful feature and in line with the philosophy >> that distinct warnings should be controlled by their own options. >> >> I would only suggest to consider changing the name to >> -Wattribute-warning, because it applies specifically to that >> attribute (as opposed to warnings about attributes in general). >> >> There are many attributes in GCC and diagnosing problems that >> are unique to each, under the same -Wattributes option, is >> becoming too coarse and overly limiting. To make it more >> flexible, I expect new options will need to be introduced, >> such as -Wattribute-alias (to control aspects of the alias >> attribute and others related to it), or -Wattribute-const >> (to control diagnostics about functions declared with >> attribute const that violate the attribute's constraints). >> >> An alternative might be to introduce a single -Wattribute= >> <attribute-list> option where the <attribute-list> gives >> the names of all the distinct attributes whose unique >> diagnostics one might need to control. >> >> Martin > > Currently there is several styles already in use: > > -Wattribute-alias where "attribute" word used as prefix for name of > attribute, > -Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of > attribute passed as possible argument, > -Wmissing-format-attribute where "attribute" word used as suffix, > -Wdeprecated-declarations where "attribute" word not used at all even if > this warning option was created especially for "deprecated" attribute. > > I changed name to "-Wattribute-warning" as you suggested, but unifying > style for all attribute related warning looks like separate activity. > Please check new patch in attachments. > Thanks for survey! I agree that making the existing options consistent (if that's what we want) should be done separately. Martin PS It doesn't look like your latest attachments made it to the list. > Updated changelog: > > gcc/Changelog > > 2018-10-14 Nikolai Merinov <n.merinov@inango-systems.com> > > * gcc/common.opt: Add -Wattribute-warning. > * gcc/doc/invoke.texi: Add documentation for > -Wno-attribute-warning. > * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test. > * gcc/expr.c (expand_expr_real_1): Add new attribute to warning_at > call to allow user configure behavior of "warning" attribute
Hi Martin, On 10/15/18 6:20 PM, Martin Sebor wrote: > On 10/15/2018 01:55 AM, Nikolai Merinov wrote: >> Hi Martin, >> >> On 10/12/18 9:58 PM, Martin Sebor wrote: >>> On 10/12/2018 04:14 AM, Nikolai Merinov wrote: >>>> Hello, >>>> >>>> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I >>>> suggested patch to have ability to control behavior of >>>> "__attribute__((warning))" in case when option "-Werror" enabled. Usage >>>> example: >>>> >>>>> #include <string.h> >>>>> int a() __attribute__((warning("Warning: `a' was used"))); >>>>> int a() { return 1; } >>>>> int main () { return a(); } >>>> >>>>> $ gcc -Werror test.c >>>>> test.c: In function ‘main’: >>>>> test.c:4:22: error: call to ‘a’ declared with attribute warning: >>>>> Warning: `a' was used [-Werror] >>>>> int main () { return a(); } >>>>> ^ >>>>> cc1: all warnings being treated as errors >>>>> $ gcc -Werror -Wno-error=warning-attribute test.c >>>>> test.c: In function ‘main’: >>>>> test.c:4:22: warning: call to ‘a’ declared with attribute warning: >>>>> Warning: `a' was used >>>>> int main () { return a(); } >>>>> ^ >>>> Can you provide any feedback on suggested changes? >>> >>> It seems like a useful feature and in line with the philosophy >>> that distinct warnings should be controlled by their own options. >>> >>> I would only suggest to consider changing the name to >>> -Wattribute-warning, because it applies specifically to that >>> attribute (as opposed to warnings about attributes in general). >>> >>> There are many attributes in GCC and diagnosing problems that >>> are unique to each, under the same -Wattributes option, is >>> becoming too coarse and overly limiting. To make it more >>> flexible, I expect new options will need to be introduced, >>> such as -Wattribute-alias (to control aspects of the alias >>> attribute and others related to it), or -Wattribute-const >>> (to control diagnostics about functions declared with >>> attribute const that violate the attribute's constraints). >>> >>> An alternative might be to introduce a single -Wattribute= >>> <attribute-list> option where the <attribute-list> gives >>> the names of all the distinct attributes whose unique >>> diagnostics one might need to control. >>> >>> Martin >> >> Currently there is several styles already in use: >> >> -Wattribute-alias where "attribute" word used as prefix for name of attribute, >> -Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of attribute passed as possible argument, >> -Wmissing-format-attribute where "attribute" word used as suffix, >> -Wdeprecated-declarations where "attribute" word not used at all even if this warning option was created especially for "deprecated" attribute. >> >> I changed name to "-Wattribute-warning" as you suggested, but unifying style for all attribute related warning looks like separate activity. Please check new patch in attachments. >> > > Thanks for survey! I agree that making the existing options > consistent (if that's what we want) should be done separately. > > Martin > > PS It doesn't look like your latest attachments made it to > the list. > Thank you for mentioning. There was my mistake. Now it's attached > >> Updated changelog: >> >> gcc/Changelog >> >> 2018-10-14 Nikolai Merinov <n.merinov@inango-systems.com> >> >> * gcc/common.opt: Add -Wattribute-warning. >> * gcc/doc/invoke.texi: Add documentation for -Wno-attribute-warning. >> * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test. >> * gcc/expr.c (expand_expr_real_1): Add new attribute to warning_at >> call to allow user configure behavior of "warning" attribute Index: gcc/common.opt =================================================================== --- gcc/common.opt (revision 265156) +++ gcc/common.opt (working copy) @@ -571,6 +571,10 @@ Wcpp Common Var(warn_cpp) Init(1) Warning Warn when a #warning directive is encountered. +Wattribute-warning +Common Var(warn_attribute_warning) Init(1) Warning +Warn about uses of __attribute__((warning)) declarations. + Wdeprecated-declarations Common Var(warn_deprecated_decl) Init(1) Warning Warn about uses of __attribute__((deprecated)) declarations. Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 265156) +++ gcc/doc/invoke.texi (working copy) @@ -291,6 +291,7 @@ Objective-C and Objective-C++ Dialects}. -Wclobbered -Wcomment -Wconditionally-supported @gol -Wconversion -Wcoverage-mismatch -Wno-cpp -Wdangling-else -Wdate-time @gol -Wdelete-incomplete @gol +-Wno-attribute-warning @gol -Wno-deprecated -Wno-deprecated-declarations -Wno-designated-init @gol -Wdisabled-optimization @gol -Wno-discarded-qualifiers -Wno-discarded-array-qualifiers @gol @@ -6950,6 +6951,15 @@ confused with the digit 0, and so is not the defau useful as a local coding convention if the programming environment cannot be fixed to display these characters distinctly. +@item -Wno-attribute-warning +@opindex Wno-attribute-warning +@opindex Wattribute-warning +Do not warn about usage of functions (@pxref{Function Attributes}) +declared with @code{warning} attribute. By default, this warning is +enabled. @option{-Wno-attribute-warning} can be used to disable the +warning or @option{-Wno-error=attribute-warning} can be used to +disable the error when compiled with @option{-Werror} flag. + @item -Wno-deprecated @opindex Wno-deprecated @opindex Wdeprecated Index: gcc/expr.c =================================================================== --- gcc/expr.c (revision 265156) +++ gcc/expr.c (working copy) @@ -10930,7 +10930,8 @@ expand_expr_real_1 (tree exp, rtx target, machine_ DECL_ATTRIBUTES (fndecl))) != NULL) { const char *ident = lang_hooks.decl_printable_name (fndecl, 1); - warning_at (tree_nonartificial_location (exp), 0, + warning_at (tree_nonartificial_location (exp), + OPT_Wattribute_warning, "%Kcall to %qs declared with attribute warning: %s", exp, identifier_to_locale (ident), TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); Index: gcc/testsuite/gcc.dg/Wno-attribute-warning.c =================================================================== --- gcc/testsuite/gcc.dg/Wno-attribute-warning.c (revision 0) +++ gcc/testsuite/gcc.dg/Wno-attribute-warning.c (working copy) @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-Werror -Wno-error=attribute-warning" } */ + +int f1(void) __attribute__ ((warning("Please avoid f1"))); +int func1(void) +{ + return f1(); /* { dg-warning "'f1' declared with attribute warning: Please avoid f1" } */ +}
Hi, What next steps should I perform in order to get this changes merged to GCC? Regards, Nikolai ----- Original Message ----- From: "Nikolai Merinov" To: "Martin Sebor" , gcc-patches@gcc.gnu.org Sent: Monday, October 15, 2018 3:21:15 PM Subject: Re: [PATCH] Add option to control warnings added through attribure "warning" Hi Martin, On 10/15/18 6:20 PM, Martin Sebor wrote: > On 10/15/2018 01:55 AM, Nikolai Merinov wrote: >> Hi Martin, >> >> On 10/12/18 9:58 PM, Martin Sebor wrote: >>> On 10/12/2018 04:14 AM, Nikolai Merinov wrote: >>>> Hello, >>>> >>>> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I >>>> suggested patch to have ability to control behavior of >>>> "__attribute__((warning))" in case when option "-Werror" enabled. Usage >>>> example: >>>> >>>>> #include >>>>> int a() __attribute__((warning("Warning: `a' was used"))); >>>>> int a() { return 1; } >>>>> int main () { return a(); } >>>> >>>>> $ gcc -Werror test.c >>>>> test.c: In function ‘main’: >>>>> test.c:4:22: error: call to ‘a’ declared with attribute warning: >>>>> Warning: `a' was used [-Werror] >>>>> int main () { return a(); } >>>>> ^ >>>>> cc1: all warnings being treated as errors >>>>> $ gcc -Werror -Wno-error=warning-attribute test.c >>>>> test.c: In function ‘main’: >>>>> test.c:4:22: warning: call to ‘a’ declared with attribute warning: >>>>> Warning: `a' was used >>>>> int main () { return a(); } >>>>> ^ >>>> Can you provide any feedback on suggested changes? >>> >>> It seems like a useful feature and in line with the philosophy >>> that distinct warnings should be controlled by their own options. >>> >>> I would only suggest to consider changing the name to >>> -Wattribute-warning, because it applies specifically to that >>> attribute (as opposed to warnings about attributes in general). >>> >>> There are many attributes in GCC and diagnosing problems that >>> are unique to each, under the same -Wattributes option, is >>> becoming too coarse and overly limiting. To make it more >>> flexible, I expect new options will need to be introduced, >>> such as -Wattribute-alias (to control aspects of the alias >>> attribute and others related to it), or -Wattribute-const >>> (to control diagnostics about functions declared with >>> attribute const that violate the attribute's constraints). >>> >>> An alternative might be to introduce a single -Wattribute= >>> option where the gives >>> the names of all the distinct attributes whose unique >>> diagnostics one might need to control. >>> >>> Martin >> >> Currently there is several styles already in use: >> >> -Wattribute-alias where "attribute" word used as prefix for name of attribute, >> -Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of attribute passed as possible argument, >> -Wmissing-format-attribute where "attribute" word used as suffix, >> -Wdeprecated-declarations where "attribute" word not used at all even if this warning option was created especially for "deprecated" attribute. >> >> I changed name to "-Wattribute-warning" as you suggested, but unifying style for all attribute related warning looks like separate activity. Please check new patch in attachments. >> > > Thanks for survey! I agree that making the existing options > consistent (if that's what we want) should be done separately. > > Martin > > PS It doesn't look like your latest attachments made it to > the list. > Thank you for mentioning. There was my mistake. Now it's attached > >> Updated changelog: >> >> gcc/Changelog >> >> 2018-10-14 Nikolai Merinov >> >> * gcc/common.opt: Add -Wattribute-warning. >> * gcc/doc/invoke.texi: Add documentation for -Wno-attribute-warning. >> * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test. >> * gcc/expr.c (expand_expr_real_1): Add new attribute to warning_at >> call to allow user configure behavior of "warning" attribute
On 10/26/2018 05:01 AM, Nikolai Merinov wrote: > Hi, > > What next steps should I perform in order to get this changes merged to GCC? Keep pinging it once a week until a maintainer approves it. I'm not empowered to do that. Martin > > Regards, > Nikolai > > ----- Original Message ----- > From: "Nikolai Merinov" > To: "Martin Sebor" , gcc-patches@gcc.gnu.org > Sent: Monday, October 15, 2018 3:21:15 PM > Subject: Re: [PATCH] Add option to control warnings added through attribure "warning" > > Hi Martin, > > On 10/15/18 6:20 PM, Martin Sebor wrote: >> On 10/15/2018 01:55 AM, Nikolai Merinov wrote: >>> Hi Martin, >>> >>> On 10/12/18 9:58 PM, Martin Sebor wrote: >>>> On 10/12/2018 04:14 AM, Nikolai Merinov wrote: >>>>> Hello, >>>>> >>>>> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I >>>>> suggested patch to have ability to control behavior of >>>>> "__attribute__((warning))" in case when option "-Werror" enabled. Usage >>>>> example: >>>>> >>>>>> #include >>>>>> int a() __attribute__((warning("Warning: `a' was used"))); >>>>>> int a() { return 1; } >>>>>> int main () { return a(); } >>>>> >>>>>> $ gcc -Werror test.c >>>>>> test.c: In function ‘main’: >>>>>> test.c:4:22: error: call to ‘a’ declared with attribute warning: >>>>>> Warning: `a' was used [-Werror] >>>>>> int main () { return a(); } >>>>>> ^ >>>>>> cc1: all warnings being treated as errors >>>>>> $ gcc -Werror -Wno-error=warning-attribute test.c >>>>>> test.c: In function ‘main’: >>>>>> test.c:4:22: warning: call to ‘a’ declared with attribute warning: >>>>>> Warning: `a' was used >>>>>> int main () { return a(); } >>>>>> ^ >>>>> Can you provide any feedback on suggested changes? >>>> >>>> It seems like a useful feature and in line with the philosophy >>>> that distinct warnings should be controlled by their own options. >>>> >>>> I would only suggest to consider changing the name to >>>> -Wattribute-warning, because it applies specifically to that >>>> attribute (as opposed to warnings about attributes in general). >>>> >>>> There are many attributes in GCC and diagnosing problems that >>>> are unique to each, under the same -Wattributes option, is >>>> becoming too coarse and overly limiting. To make it more >>>> flexible, I expect new options will need to be introduced, >>>> such as -Wattribute-alias (to control aspects of the alias >>>> attribute and others related to it), or -Wattribute-const >>>> (to control diagnostics about functions declared with >>>> attribute const that violate the attribute's constraints). >>>> >>>> An alternative might be to introduce a single -Wattribute= >>>> option where the gives >>>> the names of all the distinct attributes whose unique >>>> diagnostics one might need to control. >>>> >>>> Martin >>> >>> Currently there is several styles already in use: >>> >>> -Wattribute-alias where "attribute" word used as prefix for name of attribute, >>> -Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of attribute passed as possible argument, >>> -Wmissing-format-attribute where "attribute" word used as suffix, >>> -Wdeprecated-declarations where "attribute" word not used at all even if this warning option was created especially for "deprecated" attribute. >>> >>> I changed name to "-Wattribute-warning" as you suggested, but unifying style for all attribute related warning looks like separate activity. Please check new patch in attachments. >>> >> >> Thanks for survey! I agree that making the existing options >> consistent (if that's what we want) should be done separately. >> >> Martin >> >> PS It doesn't look like your latest attachments made it to >> the list. >> > Thank you for mentioning. There was my mistake. Now it's attached >> >>> Updated changelog: >>> >>> gcc/Changelog >>> >>> 2018-10-14 Nikolai Merinov >>> >>> * gcc/common.opt: Add -Wattribute-warning. >>> * gcc/doc/invoke.texi: Add documentation for -Wno-attribute-warning. >>> * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test. >>> * gcc/expr.c (expand_expr_real_1): Add new attribute to warning_at >>> call to allow user configure behavior of "warning" attribute
On 10/26/18 9:11 AM, Martin Sebor wrote: > On 10/26/2018 05:01 AM, Nikolai Merinov wrote: >> Hi, >> >> What next steps should I perform in order to get this changes merged >> to GCC? > > Keep pinging it once a week until a maintainer approves it. > I'm not empowered to do that. Nikolai -- your patch isn't lost. It's definitely in the queue. jeff
On 10/15/18 9:21 AM, Nikolai Merinov wrote: > Hi Martin, > > On 10/15/18 6:20 PM, Martin Sebor wrote: >> On 10/15/2018 01:55 AM, Nikolai Merinov wrote: >>> Hi Martin, >>> >>> On 10/12/18 9:58 PM, Martin Sebor wrote: >>>> On 10/12/2018 04:14 AM, Nikolai Merinov wrote: >>>>> Hello, >>>>> >>>>> In https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01795.html mail I >>>>> suggested patch to have ability to control behavior of >>>>> "__attribute__((warning))" in case when option "-Werror" enabled. >>>>> Usage >>>>> example: >>>>> >>>>>> #include <string.h> >>>>>> int a() __attribute__((warning("Warning: `a' was used"))); >>>>>> int a() { return 1; } >>>>>> int main () { return a(); } >>>>> >>>>>> $ gcc -Werror test.c >>>>>> test.c: In function ‘main’: >>>>>> test.c:4:22: error: call to ‘a’ declared with attribute warning: >>>>>> Warning: `a' was used [-Werror] >>>>>> int main () { return a(); } >>>>>> ^ >>>>>> cc1: all warnings being treated as errors >>>>>> $ gcc -Werror -Wno-error=warning-attribute test.c >>>>>> test.c: In function ‘main’: >>>>>> test.c:4:22: warning: call to ‘a’ declared with attribute warning: >>>>>> Warning: `a' was used >>>>>> int main () { return a(); } >>>>>> ^ >>>>> Can you provide any feedback on suggested changes? >>>> >>>> It seems like a useful feature and in line with the philosophy >>>> that distinct warnings should be controlled by their own options. >>>> >>>> I would only suggest to consider changing the name to >>>> -Wattribute-warning, because it applies specifically to that >>>> attribute (as opposed to warnings about attributes in general). >>>> >>>> There are many attributes in GCC and diagnosing problems that >>>> are unique to each, under the same -Wattributes option, is >>>> becoming too coarse and overly limiting. To make it more >>>> flexible, I expect new options will need to be introduced, >>>> such as -Wattribute-alias (to control aspects of the alias >>>> attribute and others related to it), or -Wattribute-const >>>> (to control diagnostics about functions declared with >>>> attribute const that violate the attribute's constraints). >>>> >>>> An alternative might be to introduce a single -Wattribute= >>>> <attribute-list> option where the <attribute-list> gives >>>> the names of all the distinct attributes whose unique >>>> diagnostics one might need to control. >>>> >>>> Martin >>> >>> Currently there is several styles already in use: >>> >>> -Wattribute-alias where "attribute" word used as prefix for name of >>> attribute, >>> -Wsuggest-attribute=[pure|const|noreturn|format|malloc] where name of >>> attribute passed as possible argument, >>> -Wmissing-format-attribute where "attribute" word used as suffix, >>> -Wdeprecated-declarations where "attribute" word not used at all even >>> if this warning option was created especially for "deprecated" >>> attribute. >>> >>> I changed name to "-Wattribute-warning" as you suggested, but >>> unifying style for all attribute related warning looks like separate >>> activity. Please check new patch in attachments. >>> >> >> Thanks for survey! I agree that making the existing options >> consistent (if that's what we want) should be done separately. >> >> Martin >> >> PS It doesn't look like your latest attachments made it to >> the list. >> > Thank you for mentioning. There was my mistake. Now it's attached >> >>> Updated changelog: >>> >>> gcc/Changelog >>> >>> 2018-10-14 Nikolai Merinov <n.merinov@inango-systems.com> >>> >>> * gcc/common.opt: Add -Wattribute-warning. >>> * gcc/doc/invoke.texi: Add documentation for >>> -Wno-attribute-warning. >>> * gcc/testsuite/gcc.dg/Wno-attribute-warning.c: New test. >>> * gcc/expr.c (expand_expr_real_1): Add new attribute to >>> warning_at >>> call to allow user configure behavior of "warning" attribute I split up the ChangeLog and fixed a very minor whitespace issue in the docs and installed the patch. I went round and round over whether or not to change the doc text. It discusses the attribute and the warning and it's easy to mix up the two. But ultimately I decided not to change it. Thanks and sorry for the long delays. Jeff >
Index: gcc/common.opt =================================================================== --- gcc/common.opt (revision 264725) +++ gcc/common.opt (working copy) @@ -571,6 +571,10 @@ Wcpp Common Var(warn_cpp) Init(1) Warning Warn when a #warning directive is encountered. +Wwarning-attribute +Common Var(warn_warning_attribute) Init(1) Warning +Warn about uses of __attribute__((warning)) declarations. + Wdeprecated-declarations Common Var(warn_deprecated_decl) Init(1) Warning Warn about uses of __attribute__((deprecated)) declarations. Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 264725) +++ gcc/doc/invoke.texi (working copy) @@ -291,6 +291,7 @@ Objective-C and Objective-C++ Dialects}. -Wclobbered -Wcomment -Wconditionally-supported @gol -Wconversion -Wcoverage-mismatch -Wno-cpp -Wdangling-else -Wdate-time @gol -Wdelete-incomplete @gol +-Wno-warning-attribute @gol -Wno-deprecated -Wno-deprecated-declarations -Wno-designated-init @gol -Wdisabled-optimization @gol -Wno-discarded-qualifiers -Wno-discarded-array-qualifiers @gol @@ -6940,6 +6941,15 @@ confused with the digit 0, and so is not the defau useful as a local coding convention if the programming environment cannot be fixed to display these characters distinctly. +@item -Wno-warning-attribute +@opindex Wno-warning-attribute +@opindex Wwarning-attribute +Do not warn about usage of functions (@pxref{Function Attributes}) +declared with @code{warning} attribute. By default, this warning is +enabled. @option{-Wno-warning-attribute} can be used to disable the +warning or @option{-Wno-error=warning-attribute} can be used to +disable the error when compiled with @option{-Werror} flag. + @item -Wno-deprecated @opindex Wno-deprecated @opindex Wdeprecated Index: gcc/expr.c =================================================================== --- gcc/expr.c (revision 264725) +++ gcc/expr.c (working copy) @@ -10930,7 +10930,8 @@ expand_expr_real_1 (tree exp, rtx target, machine_ DECL_ATTRIBUTES (fndecl))) != NULL) { const char *ident = lang_hooks.decl_printable_name (fndecl, 1); - warning_at (tree_nonartificial_location (exp), 0, + warning_at (tree_nonartificial_location (exp), + OPT_Wwarning_attribute, "%Kcall to %qs declared with attribute warning: %s", exp, identifier_to_locale (ident), TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); Index: gcc/testsuite/gcc.dg/Wno-warning-attribute.c =================================================================== --- gcc/testsuite/gcc.dg/Wno-warning-attribute.c (revision 0) +++ gcc/testsuite/gcc.dg/Wno-warning-attribute.c (working copy) @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-Werror -Wno-error=warning-attribute" } */ + +int f1(void) __attribute__ ((warning("Please avoid f1"))); +int func1(void) +{ + return f1(); /* { dg-warning "'f1' declared with attribute warning: Please avoid f1" } */ +}