[PATCH] D27486: Correct class-template deprecation behavior

Richard Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 11 15:07:24 PST 2017

rsmith added inline comments.

Comment at: include/clang/Basic/Attr.td:301
   bit DuplicatesAllowedWhileMerging = 0;
+  // Set to true if this attribute should apply to template declarations,
+  // remains false if this should only be applied to the definition.
I find this confusing -- it seems to suggest the attribute would be applied to the template declaration, not the templated declaration. I also think that the property we're modelling here is something more general than something about templates -- rather, I think the property is "is this attribute only meaningful when applied to / inherited into a defintiion?" It would also be useful to make clear that this only applies to class templates; for function templates, we always instantiate all the attributes with the declaration.

Looking through our current attribute set, it looks like at least `AbiTag` should also get this set, and maybe also `Visibility`. (Though I wonder if there would be any problem with always instantiating the full attribute set for a class declaration.)

Comment at: lib/Sema/SemaTemplate.cpp:2406-2407
+      TemplateArgLists.addOuterTemplateArguments(Converted);
+      InstantiateAttrsForDecl(TemplateArgLists,
+                              ClassTemplate->getTemplatedDecl(), Decl);
       ClassTemplate->AddSpecialization(Decl, InsertPos);
You should also presumably do this when instantiating a member `CXXRecordDecl` nested within a class template, and when instantiating a local class in a function template.

What should happen if more attributes are added between uses of the template? Example:

template<typename T> struct A;
A<int> *p;
template<typename T> struct [[deprecated]] A;
A<int> *q; // warn here?


More information about the cfe-commits mailing list