https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/183222
>From 6533cb6889cb0298a748e34f9edcabee3eedf433 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov <[email protected]> Date: Tue, 24 Feb 2026 21:51:13 -0300 Subject: [PATCH] [clang] 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. Fixes #183075 --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ASTContext.cpp | 7 +++++-- clang/test/SemaTemplate/GH183075.cpp | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 clang/test/SemaTemplate/GH183075.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index a1bb1bd2467b7..0a7b8c4a787b1 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -259,6 +259,7 @@ Bug Fixes to Attribute Support Bug Fixes to C++ Support ^^^^^^^^^^^^^^^^^^^^^^^^ +- Fixed a crash on error recovery when dealing with invalid templates. (#GH183075) - Fixed a crash when instantiating ``requires`` expressions involving substitution failures in C++ concepts. (#GH176402) - Fixed a crash when a default argument is passed to an explicit object parameter. (#GH176639) - Fixed a crash when diagnosing an invalid static member function with an explicit object parameter (#GH177741) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 3f63420cae91e..04137733e7258 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..adb0c279034bd --- /dev/null +++ b/clang/test/SemaTemplate/GH183075.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -verify %s + +int bar; +// expected-note@-1 4{{declared here}} + +int foo() +{ + // FIXME: Bad error recovery. + (void)(baz<> + baz<>); + // expected-error@-1 2{{use of undeclared identifier 'baz'; did you mean 'bar'?}} + // expected-error@-2 2{{'bar' is expected to be a non-type template, but instantiated to a class template}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
