[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

Mariya Podchishchaeva via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 14 05:19:53 PDT 2023


Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Before checking that template partial specialization is "reachable",
ensure it exists.

Fixes https://github.com/llvm/llvm-project/issues/61356


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148330

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/test/SemaCXX/undefined-partial-specialization.cpp


Index: clang/test/SemaCXX/undefined-partial-specialization.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template <typename T, bool b>
+class boo {void foo();};
+
+template <typename T>
+class boo<T, true>;
+
+template<typename T>
+void boo<T, true>::foo(){} // expected-error{{nested name specifier 'boo<T, true>::' for declaration does not refer into a class, class template or class template partial specialization}}
+
+}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===================================================================
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -125,7 +125,7 @@
             PartialSpec = ClassTemplate->findPartialSpecialization(ContextType);
           }
 
-          if (PartialSpec) {
+          if (PartialSpec && PartialSpec->hasDefinition()) {
             // A declaration of the partial specialization must be visible.
             // We can always recover here, because this only happens when we're
             // entering the context, and that can't happen in a SFINAE context.
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -301,6 +301,8 @@
   expressions/statements with invalid source locations in non-assert builds. 
   Assert builds may still see assertions triggered from this.
   (`#62105 <https://github.com/llvm/llvm-project/issues/62105>`_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 <https://github.com/llvm/llvm-project/issues/61356>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148330.513550.patch
Type: text/x-patch
Size: 1847 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230414/26b0b156/attachment.bin>


More information about the cfe-commits mailing list