[llvm-branch-commits] [clang] cb79aae - [clang] Backport: allow canonicalizing assumed template names
Douglas Yung via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Feb 28 01:26:30 PST 2026
Author: Matheus Izvekov
Date: 2026-02-28T09:26:11Z
New Revision: cb79aaed35b08a38846c5a09448870c673a88b43
URL: https://github.com/llvm/llvm-project/commit/cb79aaed35b08a38846c5a09448870c673a88b43
DIFF: https://github.com/llvm/llvm-project/commit/cb79aaed35b08a38846c5a09448870c673a88b43.diff
LOG: [clang] Backport: allow canonicalizing assumed template names
Assumed template names are part of error recovery and encode just a
declaration name, making them always canonical. This patch allows
them to be canonicalized, which is trivial.
Backport from #183222
Fixes #183075
Added:
clang/test/SemaTemplate/GH183075.cpp
Modified:
clang/lib/AST/ASTContext.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index f52470a4d7458..100e37c131ef2 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -7244,9 +7244,12 @@ TemplateName ASTContext::getCanonicalTemplateName(TemplateName Name,
return TemplateName(cast<TemplateDecl>(Template->getCanonicalDecl()));
}
- case TemplateName::OverloadedTemplate:
case TemplateName::AssumedTemplate:
- llvm_unreachable("cannot canonicalize unresolved template");
+ // An assumed template is just a name, so it is already canonical.
+ return Name;
+
+ case TemplateName::OverloadedTemplate:
+ llvm_unreachable("cannot canonicalize overloaded template");
case TemplateName::DependentTemplate: {
DependentTemplateName *DTN = Name.getAsDependentTemplateName();
diff --git a/clang/test/SemaTemplate/GH183075.cpp b/clang/test/SemaTemplate/GH183075.cpp
new file mode 100644
index 0000000000000..a9aa7d7a2157a
--- /dev/null
+++ b/clang/test/SemaTemplate/GH183075.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify %s
+
+int bar; // #bar
+
+int foo()
+{
+ // FIXME: Bad error recovery.
+ (void)(baz<> + baz<>);
+ // expected-error at -1 2{{use of undeclared identifier 'baz'; did you mean 'bar'?}}
+ // expected-note@#bar 2{{'bar' declared here}}
+ // expected-error at -3 2{{'bar' is expected to be a non-type template, but instantiated to a class template}}
+ // expected-note@#bar 2{{class template declared here}}
+}
More information about the llvm-branch-commits
mailing list