https://github.com/Serosh-commits created 
https://github.com/llvm/llvm-project/pull/190464

allow void (^)() block pointers to be used as non-type template 
parameters,especially with nullptr
fixes #189247

>From a26e8556a651d7117b2523c821ef77624fc53a66 Mon Sep 17 00:00:00 2001
From: Serosh-commits <[email protected]>
Date: Thu, 11 Dec 2025 14:39:00 +0100
Subject: [PATCH] Fix block pointer NTTP crash

---
 clang/docs/ReleaseNotes.rst     | 1 +
 clang/lib/Sema/SemaTemplate.cpp | 5 +++++
 clang/test/SemaCXX/gh189247.cpp | 4 ++++
 3 files changed, 10 insertions(+)
 create mode 100644 clang/test/SemaCXX/gh189247.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 899a4ee0dee0e..a8baf62771ded 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -549,6 +549,7 @@ Bug Fixes to Attribute Support
 
 Bug Fixes to C++ Support
 ^^^^^^^^^^^^^^^^^^^^^^^^
+- Fixed a crash when passing ``nullptr`` as a template argument for a non-type 
template parameter of block pointer type. (#GH189247)
 - Diagnose binding a reference to ``*nullptr`` during constant evaluation. 
(#GH48665)
 - Suppress ``-Wdeprecated-declarations`` in implicitly generated functions. 
(#GH147293)
 - Fix a crash when deleting a pointer to an incomplete array (#GH150359).
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 3497ff7856eed..6f6a354bc3992 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1457,6 +1457,11 @@ QualType 
Sema::CheckNonTypeTemplateParameterType(QualType T,
     return QualType();
   }
 
+  if (T->isBlockPointerType()) {
+    Diag(Loc, diag::err_template_nontype_parm_bad_type) << T;
+    return QualType();
+  }
+
   // C++ [temp.param]p4:
   //
   // A non-type template-parameter shall have one of the following
diff --git a/clang/test/SemaCXX/gh189247.cpp b/clang/test/SemaCXX/gh189247.cpp
new file mode 100644
index 0000000000000..a35cfad1d0473
--- /dev/null
+++ b/clang/test/SemaCXX/gh189247.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s
+
+template<void (^)(void)> struct T; // expected-error{{a non-type template 
parameter cannot have type 'void (^)(void)'}}
+T<nullptr> *t;

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

Reply via email to