[clang] 7c97dc2 - [clang] Do not crash on undefined template partial specialization

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 27 02:42:24 PDT 2023


Author: Mariya Podchishchaeva
Date: 2023-04-27T05:38:41-04:00
New Revision: 7c97dc20ab6148289f2cc01b2999130e32a19eb3

URL: https://github.com/llvm/llvm-project/commit/7c97dc20ab6148289f2cc01b2999130e32a19eb3
DIFF: https://github.com/llvm/llvm-project/commit/7c97dc20ab6148289f2cc01b2999130e32a19eb3.diff

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

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

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

Reviewed By: shafik, erichkeane

Differential Revision: https://reviews.llvm.org/D148330

Added: 
    clang/test/SemaCXX/undefined-partial-specialization.cpp

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaCXXScopeSpec.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ab7b2e05e54c1..f473f97f6c74e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,8 @@ Bug Fixes in This Version
   member pointer as an invalid expression.
 - Fix crash when member function contains invalid default argument.
   (`#62122 <https://github.com/llvm/llvm-project/issues/62122>`_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 <https://github.com/llvm/llvm-project/issues/61356>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index 759ed6f352c81..b11f4f1b7cdd9 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -131,7 +131,8 @@ DeclContext *Sema::computeDeclContext(const CXXScopeSpec &SS,
             // entering the context, and that can't happen in a SFINAE context.
             assert(!isSFINAEContext() && "partial specialization scope "
                                          "specifier in SFINAE context?");
-            if (!hasReachableDefinition(PartialSpec))
+            if (PartialSpec->hasDefinition() &&
+                !hasReachableDefinition(PartialSpec))
               diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
                                     MissingImportKind::PartialSpecialization,
                                     true);

diff  --git a/clang/test/SemaCXX/undefined-partial-specialization.cpp b/clang/test/SemaCXX/undefined-partial-specialization.cpp
new file mode 100644
index 0000000000000..b07a513270fd6
--- /dev/null
+++ b/clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// 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{{out-of-line definition of 'foo' from class 'boo<type-parameter-0-0, true>' without definition}}
+
+}


        


More information about the cfe-commits mailing list