Conversation
Member
|
@llvm/pr-subscribers-clang Author: Susana Monteiro (susmonteiro) ChangesIf a C++ class template rdar://166179307 Full diff: https://github.com/llvm/llvm-project/pull/173386.diff 4 Files Affected:
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5da665a5acad2..c44f4bd6b331a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -20161,7 +20161,8 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
CDecl->setIvarRBraceLoc(RBrac);
}
}
- ProcessAPINotes(Record);
+ if (!isa<ClassTemplateSpecializationDecl>(Record))
+ ProcessAPINotes(Record);
}
// Given an integral type, return the next larger integral type
diff --git a/clang/test/APINotes/Inputs/Headers/Templates.apinotes b/clang/test/APINotes/Inputs/Headers/Templates.apinotes
index b7336484da0c7..ded688b5a9076 100644
--- a/clang/test/APINotes/Inputs/Headers/Templates.apinotes
+++ b/clang/test/APINotes/Inputs/Headers/Templates.apinotes
@@ -3,3 +3,5 @@ Name: Templates
Tags:
- Name: Box
SwiftImportAs: owned
+- Name: MoveOnly
+ SwiftCopyable: false
diff --git a/clang/test/APINotes/Inputs/Headers/Templates.h b/clang/test/APINotes/Inputs/Headers/Templates.h
index 2a86a46d4af27..cdb7c3b3fa2c0 100644
--- a/clang/test/APINotes/Inputs/Headers/Templates.h
+++ b/clang/test/APINotes/Inputs/Headers/Templates.h
@@ -8,3 +8,12 @@ struct Box {
using FloatBox = Box<float>;
using IntBox = Box<int>;
+
+template <typename T>
+struct MoveOnly {
+ T value;
+};
+
+struct MoveOnlyBox {
+ MoveOnly<int> value;
+};
diff --git a/clang/test/APINotes/templates.cpp b/clang/test/APINotes/templates.cpp
index 48109011e73a9..6d8b65a0d5f85 100644
--- a/clang/test/APINotes/templates.cpp
+++ b/clang/test/APINotes/templates.cpp
@@ -1,6 +1,7 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Tmpl -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -x c++
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Tmpl -fdisable-module-hash -fapinotes-modules -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter Box -x c++ | FileCheck -check-prefix=CHECK-BOX %s
+// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Tmpl -fdisable-module-hash -fapinotes-modules -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter MoveOnly -x c++ | FileCheck -check-prefix=CHECK-MOVEONLY %s
#include "Templates.h"
@@ -10,3 +11,13 @@
// Make sure the attributes aren't duplicated.
// CHECK-BOX-NOT: SwiftAttrAttr {{.+}} <<invalid sloc>> "import_owned"
+
+// CHECK-MOVEONLY: Dumping MoveOnly:
+// CHECK-MOVEONLY-NEXT: ClassTemplateDecl {{.+}} imported in Templates MoveOnly
+// CHECK-MOVEONLY: SwiftAttrAttr {{.+}} <<invalid sloc>> "~Copyable"
+
+// CHECK-MOVEONLY-NEXT: ClassTemplateSpecializationDecl {{.+}} imported in Templates {{.+}} MoveOnly
+// CHECK-MOVEONLY: SwiftAttrAttr {{.+}} <<invalid sloc>> "~Copyable"
+
+// Make sure the attributes aren't duplicated.
+// CHECK-MOVEONLY-NOT: SwiftAttrAttr {{.+}} <<invalid sloc>> "~Copyable"
|
Xazax-hun
approved these changes
Dec 23, 2025
Collaborator
Xazax-hun
left a comment
There was a problem hiding this comment.
Overall, looks good to me. One question inline.
95a7f58 to
65c3fb3
Compare
compnerd
approved these changes
Dec 23, 2025
Xazax-hun
reviewed
Dec 23, 2025
Xazax-hun
reviewed
Dec 23, 2025
03ad2a8 to
84cdbae
Compare
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Jan 6, 2026
…emplates (llvm#173386) If a C++ class template `A` is annotated via API Notes and another class `B` has a field of type `A`, we would apply the attributes from the API Notes twice. This happened during `ActOnFields`, so this change makes sure we stop processing API Notes for class template instantiations in this function. rdar://166179307
susmonteiro
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Jan 12, 2026
…emplates (llvm#173386) If a C++ class template `A` is annotated via API Notes and another class `B` has a field of type `A`, we would apply the attributes from the API Notes twice. This happened during `ActOnFields`, so this change makes sure we stop processing API Notes for class template instantiations in this function. rdar://166179307
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a C++ class template
Ais annotated via API Notes and another classBhas a field of typeA, we would apply the attributes from the API Notes twice. This happened duringActOnFields, so this change makes sure we stop processing API Notes for class template instantiations in this function.rdar://166179307