[PATCH] D45403: Make [[maybe_unused]] work with static data members

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 9 14:21:43 PDT 2018


aaron.ballman added a comment.

I don't think we're currently diagnosing static data members of classes as being unused in the first place; are there plans to implement that functionality so that someone might want to write the attribute there?



================
Comment at: lib/Sema/SemaDeclAttr.cpp:2050
-      S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
-          << AL.getName() << ExpectedForMaybeUnused;
-      return;
----------------
`ExpectedForMaybeUnused` can be removed from AttributeList.h and the `warn_attribute_wrong_decl_type` table definition can have the entry for `ExpectedForMaybeUnused` removed as well.


================
Comment at: test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p2.cpp:5
   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]];
 };
----------------
cpplearner wrote:
> lebedev.ri wrote:
> > As the code comment noted, http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf, page 199:
> > ```
> > 2 The attribute may be applied to the declaration of a class, a typedef-name, a variable, a **non-static** data
> > member, a function, an enumeration, or an enumerator.
> > ```
> That section says that [[maybe_unused]] can be applied to a non-static data member, which doesn't mean it can't be applied to a static data member.
> 
> And I'm arguing that since a static data member is a variable, [dcl.attr.unused]p2 actually allows [[maybe_unused]] to be applied to a static data member.
Yes -- through twisty standardese, a static data member of a class might be a variable. This test case, however, is only a declaration and not a definition (which means it's not an object, which means it's not a variable). Should the attribute still appertain in this case?


Repository:
  rC Clang

https://reviews.llvm.org/D45403





More information about the cfe-commits mailing list