Skip to content

Commit

Permalink
[APINotes] Avoid duplicated attributes for class template instantiations
Browse files Browse the repository at this point in the history
If a C++ class template is annotated via API Notes, the instantiations
had the attributes repeated twice. This is because Clang was adding the
attribute twice while processing the same class template. This change
makes sure we don't try to add attributes from API Notes twice.

There is currently no way to annotate specific instantiations using API
Notes.

rdar://142539959
  • Loading branch information
egorzhdan authored Jan 15, 2025
1 parent c4443a1 commit feb7872
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 0 additions & 1 deletion clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,6 @@ DeclResult Sema::CheckClassTemplate(
NewClass->startDefinition();

ProcessDeclAttributeList(S, NewClass, Attr);
ProcessAPINotes(NewClass);

if (PrevClassTemplate)
mergeDeclAttributes(NewClass, PrevClassTemplate->getTemplatedDecl());
Expand Down
1 change: 1 addition & 0 deletions clang/test/APINotes/Inputs/Headers/Templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ struct Box {
const T* get_ptr() const { return &value; }
};

using FloatBox = Box<float>;
using IntBox = Box<int>;
3 changes: 3 additions & 0 deletions clang/test/APINotes/templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
// CHECK-BOX: Dumping Box:
// CHECK-BOX-NEXT: ClassTemplateDecl {{.+}} imported in Templates Box
// CHECK-BOX: SwiftAttrAttr {{.+}} <<invalid sloc>> "import_owned"

// Make sure the attributes aren't duplicated.
// CHECK-BOX-NOT: SwiftAttrAttr {{.+}} <<invalid sloc>> "import_owned"

0 comments on commit feb7872

Please sign in to comment.