[clang] [C++20][Modules] Fix merging of anonymous members of class templates. (PR #155948)
Michael Park via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 11 10:24:29 PDT 2025
mpark wrote:
> How these decls get merged if:
>
> ```
> // a.h
> template <typename T>
> struct S { union { T x; }; };
>
> // b.h
> import "a.h";
> inline void f(S<int> s = {}) { s.x; }
>
> // main.cpp
> import "a.h";
> void g(S<int>) {}
>
> import "b.h";
> void h() { f(); }
> ```
>
> I feel we can get some ideas from it.
In this case, because of the missing `using SI = S<int>;` in `a.h`, when we import it in `main.cpp`, there's no `ClassTemplateSpecializationDecl` to be imported from `a.h` at all. We create a new instance of `ClassTemplateSpecializationDecl` where the `isFromASTFile` is set to `false` (since we created within `main.cpp`). The "[not `isFromASTFile`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReaderDecl.cpp#L3430)" condition in this case works.
https://github.com/llvm/llvm-project/pull/155948
More information about the cfe-commits
mailing list