[clang] 17ed1e6 - [clang] diagnose block pointer types as invalid for constant template parameters (#190464)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 4 18:24:24 PDT 2026
Author: Serosh
Date: 2026-04-04T22:24:19-03:00
New Revision: 17ed1e6c4b0a5f88e087b0868c3972d4d2a4d8bf
URL: https://github.com/llvm/llvm-project/commit/17ed1e6c4b0a5f88e087b0868c3972d4d2a4d8bf
DIFF: https://github.com/llvm/llvm-project/commit/17ed1e6c4b0a5f88e087b0868c3972d4d2a4d8bf.diff
LOG: [clang] diagnose block pointer types as invalid for constant template parameters (#190464)
Fixes a crash by making it ill-formed to have a constant template
parameter with a block pointer type.
Fixes #189247
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaCXX/blocks.cpp
Removed:
################################################################################
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