[PATCH] D45403: Make [[maybe_unused]] work with static data members
S. B. Tam via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 7 03:45:08 PDT 2018
cpplearner created this revision.
cpplearner added reviewers: aaron.ballman, rsmith.
Herald added a subscriber: cfe-commits.
IIUC a static data member is a variable, so [[maybe_unused]] should be allowed to apply to a static data member.
Repository:
rC Clang
https://reviews.llvm.org/D45403
Files:
lib/Sema/SemaDeclAttr.cpp
test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp
Index: test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp
===================================================================
--- test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp
+++ 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 {
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -2042,16 +2042,6 @@
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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45403.141480.patch
Type: text/x-patch
Size: 1433 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180407/b750ac98/attachment.bin>
More information about the cfe-commits
mailing list