[clang] [clang] diagnose block pointer types as invalid for constant template parameters (PR #190464)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 4 17:05:55 PDT 2026
https://github.com/Serosh-commits updated https://github.com/llvm/llvm-project/pull/190464
>From 6645f88d531dd0cdc442ac163571c731464ba620 Mon Sep 17 00:00:00 2001
From: Serosh-commits <janmejayapanda400 at gmail.com>
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 | 4 ++++
3 files changed, 10 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..67ac7d42f52c9 100644
--- a/clang/test/SemaCXX/blocks.cpp
+++ b/clang/test/SemaCXX/blocks.cpp
@@ -163,3 +163,7 @@ void static_data_member() {
};
};
}
+
+namespace gh189247 {
+ template<void (^)()> struct A; // expected-error {{a non-type template parameter cannot have type 'void (^)()'}}
+}
More information about the cfe-commits
mailing list