[clang] Fix scope of typedefs present inside a template class (PR #146729)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 15 09:52:56 PDT 2025


ykhatav wrote:

> template <typename T = int>
> struct Y {                 
>   typedef int outside;     
>   int o;                   
> };                         
>                            
> Y<> y;                     
> Y<>::outside g;

I think the main difference stems from when Clang processes the typedef type. In the earlier test case, while processing the members of a struct, we encounter the typedef during the creation of the type for the member variable "outside." During this typedef creation, the scope is determined based on the typedef's context, which is a CXXRecordDecl (while in the RegionMap, we store ClassTemplateSpecializationDecl). In the example above, however, the typedef is created while emitting the global variable "g," and the context for the typedef is a ClassTemplateSpecializationDecl, which can be found in the RegionMap, thereby setting the correct scope for the typedef.

https://github.com/llvm/llvm-project/pull/146729


More information about the cfe-commits mailing list