https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/67522
>From 9dc31bfb012c32da7a1bf511db04df9c6c480a78 Mon Sep 17 00:00:00 2001 From: huqizhi <huqi...@feysh.com> Date: Wed, 27 Sep 2023 15:32:10 +0800 Subject: [PATCH] [clang][ASTImporter] fix clash when import `VarTemplateDecl` in record --- clang/lib/AST/ASTImporter.cpp | 3 +++ clang/unittests/AST/ASTImporterTest.cpp | 33 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index c7c2aecc8b179a4..a8ce1c469b6329c 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6240,6 +6240,9 @@ ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { // FIXME Check for ODR error if the two definitions have // different initializers? return Importer.MapImported(D, FoundDef); + if (FoundTemplate->getDeclContext()->isRecord() && + D->getDeclContext()->isRecord()) + return Importer.MapImported(D, FoundTemplate); FoundByLookup = FoundTemplate; break; diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index c90b5aaeb624306..8cbd5436c7093ae 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -4988,6 +4988,39 @@ TEST_P(ASTImporterOptionSpecificTestBase, } } +TEST_P(ImportFriendClasses, RecordVarTemplateDecl) { + Decl *ToTU = getToTuDecl( + R"( + template <class T> + class A { + public: + template <class U> + static constexpr bool X = true; + }; + )", + Lang_CXX14); + + auto *Fwd = FirstDeclMatcher<VarTemplateDecl>().match( + ToTU, varTemplateDecl(hasName("X"))); + Decl *FromTU = getTuDecl( + R"( + template <class T> + class A { + public: + template <class U> + static constexpr bool X = true; + }; + )", + Lang_CXX14, "input1.cc"); + auto *FromA = FirstDeclMatcher<VarTemplateDecl>().match( + FromTU, varTemplateDecl(hasName("X"))); + auto *ToA = Import(FromA, Lang_CXX11); + EXPECT_TRUE(ToA); + EXPECT_EQ(Fwd->getTemplatedDecl(), ToA->getTemplatedDecl()); + EXPECT_EQ(Fwd->getTemplatedDecl()->getDefinition(), + ToA->getTemplatedDecl()->getDefinition()); +} + TEST_P(ASTImporterOptionSpecificTestBase, VarTemplateParameterDeclContext) { constexpr auto Code = R"( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits