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?
Regards,
Nikolai
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" } */
+}