Skip to content

Commit 4a14372

Browse files
author
huqizhi
committed
[clang][ASTImporter] fix clash when import VarTemplateDecl in record
1 parent 134ae13 commit 4a14372

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

clang/lib/AST/ASTImporter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6240,6 +6240,9 @@ ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) {
62406240
// FIXME Check for ODR error if the two definitions have
62416241
// different initializers?
62426242
return Importer.MapImported(D, FoundDef);
6243+
if (FoundTemplate->getDeclContext()->isRecord() &&
6244+
D->getDeclContext()->isRecord())
6245+
return Importer.MapImported(D, FoundTemplate);
62436246

62446247
FoundByLookup = FoundTemplate;
62456248
break;

clang/unittests/AST/ASTImporterTest.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4988,6 +4988,37 @@ TEST_P(ASTImporterOptionSpecificTestBase,
49884988
}
49894989
}
49904990

4991+
TEST_P(ImportFriendClasses, RecordVarTemplateDecl) {
4992+
Decl *ToTU = getToTuDecl(
4993+
R"(
4994+
template <class T>
4995+
class A {
4996+
public:
4997+
template <class U>
4998+
static constexpr bool X = true;
4999+
};
5000+
)",
5001+
Lang_CXX14);
5002+
5003+
auto *ToTUX = FirstDeclMatcher<VarTemplateDecl>().match(
5004+
ToTU, varTemplateDecl(hasName("X")));
5005+
Decl *FromTU = getTuDecl(
5006+
R"(
5007+
template <class T>
5008+
class A {
5009+
public:
5010+
template <class U>
5011+
static constexpr bool X = true;
5012+
};
5013+
)",
5014+
Lang_CXX14, "input1.cc");
5015+
auto *FromX = FirstDeclMatcher<VarTemplateDecl>().match(
5016+
FromTU, varTemplateDecl(hasName("X")));
5017+
auto *ToX = Import(FromX, Lang_CXX11);
5018+
EXPECT_TRUE(ToX);
5019+
EXPECT_EQ(ToTUX, ToX);
5020+
}
5021+
49915022
TEST_P(ASTImporterOptionSpecificTestBase, VarTemplateParameterDeclContext) {
49925023
constexpr auto Code =
49935024
R"(

0 commit comments

Comments
 (0)