Skip to content

Commit 17ed1e6

Browse files
[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
1 parent 7fd02b3 commit 17ed1e6

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ Bug Fixes to Attribute Support
412412

413413
Bug Fixes to C++ Support
414414
^^^^^^^^^^^^^^^^^^^^^^^^
415+
- Clang now rejects constant template parameters with block pointer types, since these are not implemented anyway and would lead to crashes. (#GH189247)
415416
- Fixed a crash on error recovery when dealing with invalid templates. (#GH183075)
416417
- Fixed a crash when instantiating ``requires`` expressions involving substitution failures in C++ concepts. (#GH176402)
417418
- Fixed an incorrect template argument deduction when matching packs of template

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,11 @@ QualType Sema::CheckNonTypeTemplateParameterType(QualType T,
14591459
return QualType();
14601460
}
14611461

1462+
if (T->isBlockPointerType()) {
1463+
Diag(Loc, diag::err_template_nontype_parm_bad_type) << T;
1464+
return QualType();
1465+
}
1466+
14621467
// C++ [temp.param]p4:
14631468
//
14641469
// A non-type template-parameter shall have one of the following

clang/test/SemaCXX/blocks.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,7 @@ void static_data_member() {
163163
};
164164
};
165165
}
166+
167+
namespace gh189247 {
168+
template<void (^)()> struct A; // expected-error {{a non-type template parameter cannot have type 'void (^)()'}}
169+
}

0 commit comments

Comments
 (0)