https://github.com/Serosh-commits created https://github.com/llvm/llvm-project/pull/190377
allow `void (^)()` block pointers to be used as non-type template parameters,especially with `nullptr` fixes #189247 >From 4310226da298c35103a7269c99d5568489e4e7d4 Mon Sep 17 00:00:00 2001 From: Serosh-commits <[email protected]> Date: Fri, 3 Apr 2026 23:14:48 +0530 Subject: [PATCH] Fix block pointer NTTP crash --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaTemplate.cpp | 4 +++- clang/test/SemaCXX/gh189247.cpp | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/gh189247.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 442ec58adc25a..1f405982ca0fe 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -427,6 +427,8 @@ Bug Fixes to C++ Support - Fixed a crash when an immediate-invoked ``consteval`` lambda is used as an invalid initializer. (#GH185270) - Fixed an assertion failure when using a global destructor with a target with a non-default program address space. (#GH186484) +- Fixed a crash when passing ``nullptr`` as a template argument for a non-type template parameter of block pointer type. (#GH189247) + - Inherited constructors in ``dllexport`` classes are now exported for ABI-compatible cases, matching MSVC behavior. Constructors with variadic arguments or callee-cleanup parameters are not yet supported and produce a warning. (#GH162640) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index aa72cb8fa2895..d03ca7ae7b071 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -1472,6 +1472,8 @@ QualType Sema::CheckNonTypeTemplateParameterType(QualType T, T->isLValueReferenceType() || // -- pointer to member, T->isMemberPointerType() || + // -- block pointer, + T->isBlockPointerType() || // -- std::nullptr_t, or T->isNullPtrType() || // -- a type that contains a placeholder type. @@ -7355,7 +7357,7 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, QualType ParamType, // For a non-type template-parameter of pointer or reference type, // the value of the constant expression shall not refer to assert(ParamType->isPointerOrReferenceType() || - ParamType->isNullPtrType()); + ParamType->isNullPtrType() || ParamType->isBlockPointerType()); // -- a temporary object // -- a string literal // -- the result of a typeid expression, or diff --git a/clang/test/SemaCXX/gh189247.cpp b/clang/test/SemaCXX/gh189247.cpp new file mode 100644 index 0000000000000..79f7b312aee83 --- /dev/null +++ b/clang/test/SemaCXX/gh189247.cpp @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s +// expected-no-diagnostics + +template<void (^)(void)> struct T; +T<nullptr> *t; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
