Skip to content

[clang] fix getTrivialTemplateArgumentLoc template template argument #153344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2025

Conversation

mizvekov
Copy link
Contributor

@mizvekov mizvekov commented Aug 13, 2025

This fixes a regression reported here #147835 (comment), where getTrivialTemplateArgumentLoc can't see through template name sugar when producing a trivial TemplateArgumentLoc for template template arguments.

Since this regression was never released, there are no release notes.

This fixes a regression introduced by GH147835, where getTrivialTemplateArgumentLoc
can't see through template name sugar when producing a trivial
TemplateArgumentLoc for template template arguments.

Since this regression was enever released, there are no release notes.
@mizvekov mizvekov self-assigned this Aug 13, 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 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 13, 2025

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

Changes

This fixes a regression introduced by #147835, where getTrivialTemplateArgumentLoc can't see through template name sugar when producing a trivial TemplateArgumentLoc for template template arguments.

Since this regression was never released, there are no release notes.


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+1-5)
  • (modified) clang/test/SemaTemplate/ctad.cpp (+14)
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 3aa808e165bb6..477f8c7541939 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2911,11 +2911,7 @@ Sema::getTrivialTemplateArgumentLoc(const TemplateArgument &Arg,
     case TemplateArgument::TemplateExpansion: {
       NestedNameSpecifierLocBuilder Builder;
       TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
-      if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
-        Builder.MakeTrivial(Context, DTN->getQualifier(), Loc);
-      else if (QualifiedTemplateName *QTN =
-                   Template.getAsQualifiedTemplateName())
-        Builder.MakeTrivial(Context, QTN->getQualifier(), Loc);
+      Builder.MakeTrivial(Context, Template.getQualifier(), Loc);
       return TemplateArgumentLoc(
           Context, Arg, Loc, Builder.getWithLocInContext(Context), Loc,
           /*EllipsisLoc=*/Arg.getKind() == TemplateArgument::TemplateExpansion
diff --git a/clang/test/SemaTemplate/ctad.cpp b/clang/test/SemaTemplate/ctad.cpp
index 49c46150d964c..1a575ea527006 100644
--- a/clang/test/SemaTemplate/ctad.cpp
+++ b/clang/test/SemaTemplate/ctad.cpp
@@ -90,3 +90,17 @@ namespace AsValueParameter {
   // cxx17-error@-1 {{value of type 'foo::A<int>' is not implicitly convertible to 'int'}}
   // cxx20-error@-2 {{non-type template parameter has non-literal type 'foo::A<int>' (aka 'AsValueParameter::foo::A<int>')}}
 } // namespace AsValueParameter
+
+namespace ConvertDeducedTemplateArgument {
+  namespace A {
+    template <class> struct B {};
+  }
+
+  template <template <class> class TT1> struct C {
+    C(TT1<int>);
+  };
+
+  template <template <class> class TT2> using D = TT2<int>;
+
+  auto x = C(D<A::B>());
+}

@mizvekov mizvekov merged commit 73feab5 into main Aug 13, 2025
12 checks passed
@mizvekov mizvekov deleted the users/mizvekov/fix-regression-GH147835-1 branch August 13, 2025 05:09
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Aug 13, 2025
@zwuis zwuis added the skip-precommit-approval PR for CI feedback, not intended for review label Aug 14, 2025
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Aug 14, 2025
…lvm#153344)

This fixes a regression reported here
llvm#147835 (comment),
where getTrivialTemplateArgumentLoc can't see through template name
sugar when producing a trivial TemplateArgumentLoc for template template
arguments.

Since this regression was never released, there are no release notes.
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
Development

Successfully merging this pull request may close these issues.

3 participants