aaron.ballman added inline comments.

================
Comment at: lib/Sema/SemaDeclAttr.cpp:2054
-  }
-
   // If this is spelled as the standard C++17 attribute, but not in C++17, warn
----------------
Quuxplusone wrote:
> @aaron.ballman writes:
> > 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?
> 
> FWIW, "plans to implement that functionality" (in Clang) is not the only 
> reason to accept the attribute. Someone might write the attribute in their 
> codebase that currently compiles with some //other// compiler which 
> implements the functionality (or at least does not reject it); it would be 
> mildly unfortunate if that made their codebase non-portable-to-Clang. (Only 
> "mildly" because the diagnostic being removed here is just a warning; the 
> user could suppress it if they really needed to.)
> 
> Here's an example of code that compiles cleanly with GCC but gives an 
> arguably "false positive" diagnostic when compiled with Clang.
> https://wandbox.org/permlink/UG4kG5XTBn12xfuu
> Now, admittedly, both GCC and Clang produce a "false negative" re the unused 
> private static member `y`; but that false negative might get fixed in the 
> future. The user writes their code //today// and it must compile //today//. :)
> 
Agreed; that's why the analysis isn't a requirement for accepting this patch. I 
was mostly just curious if there were plans to extend that functionality or not.


================
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]];
 };
----------------
Quuxplusone wrote:
> aaron.ballman wrote:
> > 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?
> The attribute does currently apply to declarations as well as definitions, 
> although you have to be a real language lawyer to observe it.
> https://wandbox.org/permlink/WBLWBdd42rv95UaS
Good point. Also, declaration vs definition doesn't really matter when I think 
about it -- the whole point is to tell you "hey, this is unused" and give the 
programmer a way to say "maybbbbbe it's unused, but shut up about it anyway." 
Definition vs declaration doesn't much matter in that case.


Repository:
  rC Clang

https://reviews.llvm.org/D45403



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to