]> granicus.if.org Git - clang/commitdiff
Allow [[maybe_unused]] on static data members; these are considered variables and...
authorAaron Ballman <aaron@aaronballman.com>
Thu, 12 Apr 2018 12:21:41 +0000 (12:21 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Thu, 12 Apr 2018 12:21:41 +0000 (12:21 +0000)
Patch by S. B. Tam.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329904 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/AttributeList.h
lib/Sema/SemaDeclAttr.cpp
test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp

index d8f478b29f0be99338575a711c24e90a6cc7384a..0b0b103060741fd85b41f2a252805fe82c2a4060 100644 (file)
@@ -2834,8 +2834,7 @@ def warn_attribute_wrong_decl_type : Warning<
   "|types and namespaces"
   "|variables, functions and classes"
   "|kernel functions"
-  "|non-K&R-style functions"
-  "|variables, functions, methods, types, enumerations, enumerators, labels, and non-static data members}1">,
+  "|non-K&R-style functions}1">,
   InGroup<IgnoredAttributes>;
 def err_attribute_wrong_decl_type : Error<warn_attribute_wrong_decl_type.Text>;
 def warn_type_attribute_wrong_type : Warning<
index 4508d4466b89eccca34a710f325ac3b29dc0cb7d..4ad4a895195fd1757c37371975efee021550655e 100644 (file)
@@ -928,7 +928,6 @@ enum AttributeDeclKind {
   ExpectedFunctionVariableOrClass,
   ExpectedKernelFunction,
   ExpectedFunctionWithProtoType,
-  ExpectedForMaybeUnused,
 };
 
 } // namespace clang
index d4398cef881cfdf84a24fba10a325490925ae506..23528f3eb28515821d9fbef3aa37006735bb3c62 100644 (file)
@@ -2042,16 +2042,6 @@ static void handleDependencyAttr(Sema &S, Scope *Scope, Decl *D,
 static void handleUnusedAttr(Sema &S, Decl *D, const AttributeList &AL) {
   bool IsCXX17Attr = AL.isCXX11Attribute() && !AL.getScopeName();
 
-  if (IsCXX17Attr && isa<VarDecl>(D)) {
-    // The C++17 spelling of this attribute cannot be applied to a static data
-    // member per [dcl.attr.unused]p2.
-    if (cast<VarDecl>(D)->isStaticDataMember()) {
-      S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
-          << AL.getName() << ExpectedForMaybeUnused;
-      return;
-    }
-  }
-
   // If this is spelled as the standard C++17 attribute, but not in C++17, warn
   // about using it as an extension.
   if (!S.getLangOpts().CPlusPlus17 && IsCXX17Attr)
index b539ca48ae34dbd16e43ef236037235fdf63991f..db1886894d74639b9b251ccfbdb04fee47a23162 100644 (file)
@@ -2,7 +2,7 @@
 
 struct [[maybe_unused]] S {
   int I [[maybe_unused]];
-  static int SI [[maybe_unused]]; // expected-warning {{'maybe_unused' attribute only applies to variables, functions, methods, types, enumerations, enumerators, labels, and non-static data members}}
+  static int SI [[maybe_unused]];
 };
 
 enum [[maybe_unused]] E1 {