Skip to content

Commit 4bceb00

Browse files
committed
[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 (cherry picked from commit feb7872)
1 parent bb5a462 commit 4bceb00

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
@@ -2119,7 +2119,6 @@ DeclResult Sema::CheckClassTemplate(
21192119
NewClass->startDefinition();
21202120

21212121
ProcessDeclAttributeList(S, NewClass, Attr);
2122-
ProcessAPINotes(NewClass);
21232122

21242123
if (PrevClassTemplate)
21252124
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)