r329904 - Allow [[maybe_unused]] on static data members; these are considered variables and the attribute should appertain to them.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 12 05:21:41 PDT 2018
Author: aaronballman
Date: Thu Apr 12 05:21:41 2018
New Revision: 329904
URL: http://llvm.org/viewvc/llvm-project?rev=329904&view=rev
Log:
Allow [[maybe_unused]] on static data members; these are considered variables and the attribute should appertain to them.
Patch by S. B. Tam.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/AttributeList.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=329904&r1=329903&r2=329904&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 12 05:21:41 2018
@@ -2834,8 +2834,7 @@ def warn_attribute_wrong_decl_type : War
"|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<
Modified: cfe/trunk/include/clang/Sema/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=329904&r1=329903&r2=329904&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/AttributeList.h (original)
+++ cfe/trunk/include/clang/Sema/AttributeList.h Thu Apr 12 05:21:41 2018
@@ -928,7 +928,6 @@ enum AttributeDeclKind {
ExpectedFunctionVariableOrClass,
ExpectedKernelFunction,
ExpectedFunctionWithProtoType,
- ExpectedForMaybeUnused,
};
} // namespace clang
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=329904&r1=329903&r2=329904&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Apr 12 05:21:41 2018
@@ -2042,16 +2042,6 @@ static void handleDependencyAttr(Sema &S
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)
Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp?rev=329904&r1=329903&r2=329904&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp Thu Apr 12 05:21:41 2018
@@ -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 {
More information about the cfe-commits
mailing list