Skip to content

Commit feb7872

Browse files
authored
[APINotes] Avoid duplicated attributes for class template instantiations
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
1 parent c4443a1 commit feb7872

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,6 @@ DeclResult Sema::CheckClassTemplate(
21452145
NewClass->startDefinition();
21462146

21472147
ProcessDeclAttributeList(S, NewClass, Attr);
2148-
ProcessAPINotes(NewClass);
21492148

21502149
if (PrevClassTemplate)
21512150
mergeDeclAttributes(NewClass, PrevClassTemplate->getTemplatedDecl());

clang/test/APINotes/Inputs/Headers/Templates.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ struct Box {
66
const T* get_ptr() const { return &value; }
77
};
88

9+
using FloatBox = Box<float>;
910
using IntBox = Box<int>;

clang/test/APINotes/templates.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
// CHECK-BOX: Dumping Box:
88
// CHECK-BOX-NEXT: ClassTemplateDecl {{.+}} imported in Templates Box
99
// CHECK-BOX: SwiftAttrAttr {{.+}} <<invalid sloc>> "import_owned"
10+
11+
// Make sure the attributes aren't duplicated.
12+
// CHECK-BOX-NOT: SwiftAttrAttr {{.+}} <<invalid sloc>> "import_owned"

0 commit comments

Comments
 (0)