https://github.com/Serosh-commits updated https://github.com/llvm/llvm-project/pull/190464
>From ada1b64e190ad22993e96b457ea2c377e3186b14 Mon Sep 17 00:00:00 2001 From: Serosh-commits <[email protected]> Date: Sun, 5 Apr 2026 05:08:24 +0530 Subject: [PATCH] [Clang] Diagnose block pointer types as invalid for constant template parameters --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaTemplate.cpp | 5 +++++ clang/test/SemaCXX/blocks.cpp | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 2fe76e60946f5..1601be699a604 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -412,6 +412,7 @@ Bug Fixes to Attribute Support Bug Fixes to C++ Support ^^^^^^^^^^^^^^^^^^^^^^^^ +- Clang now rejects constant template parameters with block pointer types, since these are not implemented anyway and would lead to crashes. (#GH189247) - 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 an incorrect template argument deduction when matching packs of template diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index aa72cb8fa2895..4306e32104e9b 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -1459,6 +1459,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/blocks.cpp b/clang/test/SemaCXX/blocks.cpp index 997ac2b5721df..30a8b1d486fff 100644 --- a/clang/test/SemaCXX/blocks.cpp +++ b/clang/test/SemaCXX/blocks.cpp @@ -163,3 +163,8 @@ void static_data_member() { }; }; } + +namespace gh189247 { + template<void (^)()> struct A; // expected-error {{a non-type template parameter cannot have type 'void (^)()'}} + A<nullptr> *a; +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
