llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

<details>
<summary>Changes</summary>

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

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4-3) 
- (modified) clang/lib/AST/ASTContext.cpp (+5-2) 
- (added) clang/test/SemaTemplate/GH183075.cpp (+12) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a1bb1bd2467b7..80e78f55e3c07 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)
@@ -360,7 +361,7 @@ AST Matchers
 
 clang-format
 ------------
-- Add ``ObjCSpaceAfterMethodDeclarationPrefix`` option to control space 
between the 
+- Add ``ObjCSpaceAfterMethodDeclarationPrefix`` option to control space 
between the
   '-'/'+' and the return type in Objective-C method declarations
 
 libclang
@@ -395,8 +396,8 @@ Python Binding Changes
   Affected methods: ``isKindOptional``, ``isKindTypedText``, 
``isKindPlaceHolder``,
   ``isKindInformative`` and ``isKindResultType``.
 - Add a deprecation warning to ``CodeCompletionResults.results``.
-  This property will become an implementation detail with changed behavior in 
a 
-  future release and should not be used directly.. Existing uses of 
+  This property will become an implementation detail with changed behavior in a
+  future release and should not be used directly.. Existing uses of
   ``CodeCompletionResults.results`` should be changed to directly use
   ``CodeCompletionResults``: it nows supports ``__len__`` and ``__getitem__``,
   so it can be used the same as ``CodeCompletionResults.results``.
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}}
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/183222
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to