aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2022-07-25 17:43:52 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2022-07-25 17:57:02 +0800
commitd35134485a6cd1b0e25b5dccd330678b9e57919d (patch)
treeacc466a09a12af1decb0fa45422ab5653a7c3734 /clang/unittests
parentb14d7bf75079705f35809533eb5278e56ac61917 (diff)
downloadllvm-d35134485a6cd1b0e25b5dccd330678b9e57919d.zip
llvm-d35134485a6cd1b0e25b5dccd330678b9e57919d.tar.gz
llvm-d35134485a6cd1b0e25b5dccd330678b9e57919d.tar.bz2
[C++20] [Modules] Make the linkage consistent for class template and its
specialization Previously in D120397, we've handled the linkage for function template and its specialization. But we forgot to handle it for class templates and their specialization. So we make it in the patch with the similar approach.
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/AST/DeclTest.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/clang/unittests/AST/DeclTest.cpp b/clang/unittests/AST/DeclTest.cpp
index 560c6b3..71835a0 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -179,7 +179,14 @@ TEST(Decl, InConsistLinkageForTemplates) {
void f() {}
template <>
- void f<int>() {})");
+ void f<int>() {}
+
+ export template <class T>
+ class C {};
+
+ template<>
+ class C<int> {};
+ )");
auto AST =
tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
@@ -193,6 +200,18 @@ TEST(Decl, InConsistLinkageForTemplates) {
const FunctionDecl *SpecializedF = Funcs[1].getNodeAs<FunctionDecl>("f");
EXPECT_EQ(TemplateF->getLinkageInternal(),
SpecializedF->getLinkageInternal());
+
+ llvm::SmallVector<ast_matchers::BoundNodes, 1> ClassTemplates =
+ match(classTemplateDecl().bind("C"), Ctx);
+ llvm::SmallVector<ast_matchers::BoundNodes, 1> ClassSpecializations =
+ match(classTemplateSpecializationDecl().bind("C"), Ctx);
+
+ EXPECT_EQ(ClassTemplates.size(), 1U);
+ EXPECT_EQ(ClassSpecializations.size(), 1U);
+ const NamedDecl *TemplatedC = ClassTemplates[0].getNodeAs<NamedDecl>("C");
+ const NamedDecl *SpecializedC = ClassSpecializations[0].getNodeAs<NamedDecl>("C");
+ EXPECT_EQ(TemplatedC->getLinkageInternal(),
+ SpecializedC->getLinkageInternal());
}
TEST(Decl, ModuleAndInternalLinkage) {