From 010f67d24187508c82d72163ce2d574d5cc04c8e Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 12 Apr 2018 12:21:41 +0000 Subject: [PATCH] Allow [[maybe_unused]] on static data members; these are considered variables and the attribute should appertain to them. 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 | 3 +-- include/clang/Sema/AttributeList.h | 1 - lib/Sema/SemaDeclAttr.cpp | 10 ---------- test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp | 2 +- 4 files changed, 2 insertions(+), 14 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index d8f478b29f..0b0b103060 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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; def err_attribute_wrong_decl_type : Error; def warn_type_attribute_wrong_type : Warning< diff --git a/include/clang/Sema/AttributeList.h b/include/clang/Sema/AttributeList.h index 4508d4466b..4ad4a89519 100644 --- a/include/clang/Sema/AttributeList.h +++ b/include/clang/Sema/AttributeList.h @@ -928,7 +928,6 @@ enum AttributeDeclKind { ExpectedFunctionVariableOrClass, ExpectedKernelFunction, ExpectedFunctionWithProtoType, - ExpectedForMaybeUnused, }; } // namespace clang diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index d4398cef88..23528f3eb2 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -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(D)) { - // The C++17 spelling of this attribute cannot be applied to a static data - // member per [dcl.attr.unused]p2. - if (cast(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) diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp index b539ca48ae..db1886894d 100644 --- a/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp +++ b/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp @@ -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 { -- 2.40.0