[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)
Qizhi Hu via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 13 00:39:59 PST 2023
jcsxky wrote:
> The `VisitTypeAliasTemplateDecl` function should be re-designed to check for structural equivalence at import. The following test does not pass because an existing `TypeAliasTemplateDecl` declaration with the same name is always found and returned, without check for structural equivalence.
>
> ```
> TEST_P(ASTImporterOptionSpecificTestBase, ImportTypeAliasTemplateDecl1) {
> const char *ToCode =
> R"(
> struct S;
> template <typename, typename>
> using Callable = S;
> )";
> const char *Code =
> R"(
> struct S;
> template <typename>
> using Callable = S;
> )";
> Decl *ToTU = getToTuDecl(ToCode, Lang_CXX17);
> Decl *FromTU = getTuDecl(Code, Lang_CXX17);
>
> auto *FromCallable = FirstDeclMatcher<TypeAliasTemplateDecl>().match(
> FromTU, typeAliasTemplateDecl(hasName("Callable")));
>
> auto *ToCallable = FirstDeclMatcher<TypeAliasTemplateDecl>().match(
> ToTU, typeAliasTemplateDecl(hasName("Callable")));
>
> auto *ImportedCallable = Import(FromCallable, Lang_CXX17);
> EXPECT_TRUE(ImportedCallable);
> EXPECT_NE(ImportedCallable, ToCallable);
> }
> ```
>
> Additionally I discovered that import of `ClassTemplateDecl` is not correct too: If there is an object with the same name that is not a `ClassTemplateDecl`, it is just ignored at import. This is not correct, the existing object may cause name conflict (for example it can be a non-template `RecordDecl`). (I found this when checking the questions in my last comment.) This is an independent problem but should be fixed.
I pulled the latest code of main branch and found it seems incorrect with the test case I have supplied. I will have a double check this pr and issues you mentioned here. Thank for your detail comments and guidance.
https://github.com/llvm/llvm-project/pull/74919
More information about the cfe-commits
mailing list