Skip to content

Conversation

mizvekov
Copy link
Contributor

When building the base type for constructor initializer, the case of an UnresolvedUsingType was not being handled.

For the non-dependent case, we are also skipping adding the UsingType, but this is just missing information in the AST. A FIXME for this is added.

This fixes a regression introduced in #147835, which was never released, so there are no release notes.

Fixes #154436

When building the base type for constructor initializer, the case of an
UnresolvedUsingType was not being handled.

For the non-dependent case, we are also skipping adding the UsingType, but
this is just missing information in the AST. A FIXME for this is added.

This fixes a regression introduced in #147835, which was never released, so
there are no release notes.

Fixes #154436
@mizvekov mizvekov self-assigned this Aug 20, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Aug 20, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 20, 2025

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

Changes

When building the base type for constructor initializer, the case of an UnresolvedUsingType was not being handled.

For the non-dependent case, we are also skipping adding the UsingType, but this is just missing information in the AST. A FIXME for this is added.

This fixes a regression introduced in #147835, which was never released, so there are no release notes.

Fixes #154436


Full diff: https://github.com/llvm/llvm-project/pull/154592.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaDeclCXX.cpp (+7)
  • (modified) clang/test/SemaTemplate/class-template-ctor-initializer.cpp (+11-2)
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index fb9cec1b78764..aa7de722c3e94 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -4568,6 +4568,7 @@ Sema::BuildMemInitializer(Decl *ConstructorD,
       MarkAnyDeclReferenced(TyD->getLocation(), TyD, /*OdrUse=*/false);
 
       TypeLocBuilder TLB;
+      // FIXME: This is missing building the UsingType for TyD, if any.
       if (const auto *TD = dyn_cast<TagDecl>(TyD)) {
         BaseType = Context.getTagType(ElaboratedTypeKeyword::None,
                                       SS.getScopeRep(), TD, /*OwnsTag=*/false);
@@ -4581,6 +4582,12 @@ Sema::BuildMemInitializer(Decl *ConstructorD,
         TLB.push<TypedefTypeLoc>(BaseType).set(
             /*ElaboratedKeywordLoc=*/SourceLocation(),
             SS.getWithLocInContext(Context), IdLoc);
+      } else if (auto *UD = dyn_cast<UnresolvedUsingTypenameDecl>(TyD)) {
+        BaseType = Context.getUnresolvedUsingType(ElaboratedTypeKeyword::None,
+                                                  SS.getScopeRep(), UD);
+        TLB.push<UnresolvedUsingTypeLoc>(BaseType).set(
+            /*ElaboratedKeywordLoc=*/SourceLocation(),
+            SS.getWithLocInContext(Context), IdLoc);
       } else {
         // FIXME: What else can appear here?
         assert(SS.isEmpty());
diff --git a/clang/test/SemaTemplate/class-template-ctor-initializer.cpp b/clang/test/SemaTemplate/class-template-ctor-initializer.cpp
index 6dae20774585e..43a3986fea845 100644
--- a/clang/test/SemaTemplate/class-template-ctor-initializer.cpp
+++ b/clang/test/SemaTemplate/class-template-ctor-initializer.cpp
@@ -4,8 +4,8 @@
 
 template<class X> struct A {};
 
-template<class X> struct B : A<X> { 
-  B() : A<X>() {} 
+template<class X> struct B : A<X> {
+  B() : A<X>() {}
 };
 B<int> x;
 
@@ -76,3 +76,12 @@ namespace NonDependentError {
   Derived1<void> d1;
   Derived2<void> d2;
 }
+
+namespace UnresolvedUsing {
+  template <class T> class A {
+    using typename T::B;
+    struct C : B {
+      C() : B() {}
+    };
+  };
+} // namespace UnresolvedUsing

@mizvekov mizvekov merged commit e1dbe09 into main Aug 20, 2025
12 checks passed
@mizvekov mizvekov deleted the users/mizvekov/GH154436 branch August 20, 2025 19:24
@zwuis zwuis added the skip-precommit-approval PR for CI feedback, not intended for review label Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category skip-precommit-approval PR for CI feedback, not intended for review
Projects
None yet
3 participants