diff options
-rw-r--r-- | gcc/c-family/c-attribs.c | 1 | ||||
-rw-r--r-- | gcc/doc/extend.texi | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/diagnostic/maybe_unused1.C | 17 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/attrib62.C | 2 |
4 files changed, 22 insertions, 4 deletions
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index 42026a8..6bf492a 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -1568,6 +1568,7 @@ handle_unused_attribute (tree *node, tree name, tree ARG_UNUSED (args), || VAR_OR_FUNCTION_DECL_P (decl) || TREE_CODE (decl) == LABEL_DECL || TREE_CODE (decl) == CONST_DECL + || TREE_CODE (decl) == FIELD_DECL || TREE_CODE (decl) == TYPE_DECL) { TREE_USED (decl) = 1; diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 408979b..8fc66d6 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -7516,9 +7516,9 @@ Not all targets support this attribute. @item unused @cindex @code{unused} variable attribute -This attribute, attached to a variable, means that the variable is meant -to be possibly unused. GCC does not produce a warning for this -variable. +This attribute, attached to a variable or structure field, means that +the variable or field is meant to be possibly unused. GCC does not +produce a warning for this variable or field. @item used @cindex @code{used} variable attribute diff --git a/gcc/testsuite/g++.dg/diagnostic/maybe_unused1.C b/gcc/testsuite/g++.dg/diagnostic/maybe_unused1.C new file mode 100644 index 0000000..70a8ec9 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/maybe_unused1.C @@ -0,0 +1,17 @@ +/* [dcl.attr.unused] The attribute may be applied to the declaration of a + class, a typedef-name, a variable (including a structured binding + declaration), a non-static data member, a function, an enumeration, or an + enumerator. */ +// { dg-do compile { target c++11 } } +// { dg-additional-options "-Wunused -Wextra" } + +class [[maybe_unused]] Test { + [[maybe_unused]] int a_; + void b() {}; +}; + +[[maybe_unused]] typedef Test Test2; + +[[maybe_unused]] int i; +[[maybe_unused]] void f(); +enum [[maybe_unused]] E { e [[maybe_unused]] = 42 }; diff --git a/gcc/testsuite/g++.dg/ext/attrib62.C b/gcc/testsuite/g++.dg/ext/attrib62.C index 116ee82..d34cd25 100644 --- a/gcc/testsuite/g++.dg/ext/attrib62.C +++ b/gcc/testsuite/g++.dg/ext/attrib62.C @@ -3,5 +3,5 @@ template<typename T> struct A { - T a, __attribute((unused)) b; // { dg-warning "attribute ignored" } + T a, __attribute((unused)) b; }; |