Skip to content

Commit 5801970

Browse files
[SYCL] Use SFINAE to reject wrong signature of CGF object parameter (#11157)
For a mistake like this: ``` q.submit([&](sycl::handler cgh) { // Missing "&" cgh.single_task([=]() {}); }).wait_and_throw(); ``` changes errors from ``` In file included from <...>/build/bin/../include/sycl/sycl.hpp:16: In file included from <...>/build/bin/../include/sycl/backend.hpp:34: <...>/build/bin/../include/sycl/queue.hpp:361:18: error: no matching member function for call to 'submit_impl' 361 | auto Event = submit_impl(CGF, CodeLoc); | ^~~~~~~~~~~ a.cpp:5:5: note: in instantiation of function template specialization 'sycl::queue::submit<(lambda at a.cpp:5:12)>' requested here 5 | q.submit([&](sycl::handler cgh) { | ^ <...>/build/bin/../include/sycl/queue.hpp:2811:9: note: candidate function not viable: no known conversion from '(lambda at a.cpp:5:12)' to 'std::function<void (handler &)>' for 1st argument 2811 | event submit_impl(std::function<void(handler &)> CGH, | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <...>/build/bin/../include/sycl/queue.hpp:2814:9: note: candidate function not viable: requires 3 arguments, but 2 were provided 2814 | event submit_impl(std::function<void(handler &)> CGH, queue secondQueue, | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2815 | const detail::code_location &CodeLoc); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. ``` to ``` a.cpp:5:5: error: no matching member function for call to 'submit' 5 | q.submit([&](sycl::handler cgh) { | ~~^~~~~~ <...>/build/bin/../include/sycl/queue.hpp:344:3: note: candidate template ignored: requirement 'std::is_convertible_v<(lambda at a.cpp:5:12), std::function<void (sycl::handler &)>>' was not satisfied [with T = (lambda at a.cpp:5:12)] 344 | submit(T CGF, const detail::code_location &CodeLoc = | ^ <...>/build/bin/../include/sycl/queue.hpp:382:3: note: candidate function template not viable: requires at least 2 arguments, but 1 was provided 382 | submit( | ^ 383 | T CGF, queue &SecondaryQueue, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 384 | const detail::code_location &CodeLoc = detail::code_location::current()) { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. ```
1 parent 2744b41 commit 5801970

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sycl/include/sycl/queue.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,10 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
339339
/// \param CodeLoc is the code location of the submit call (default argument)
340340
/// \return a SYCL event object for the submitted command group.
341341
template <typename T>
342-
event submit(T CGF, const detail::code_location &CodeLoc =
343-
detail::code_location::current()) {
342+
std::enable_if_t<std::is_convertible_v<T, std::function<void(handler &)>>,
343+
event>
344+
submit(T CGF, const detail::code_location &CodeLoc =
345+
detail::code_location::current()) {
344346
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
345347
#if __SYCL_USE_FALLBACK_ASSERT
346348
auto PostProcess = [this, &CodeLoc](bool IsKernel, bool KernelUsesAssert,
@@ -375,7 +377,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
375377
/// \return a SYCL event object, which corresponds to the queue the command
376378
/// group is being enqueued on.
377379
template <typename T>
378-
event submit(
380+
std::enable_if_t<std::is_convertible_v<T, std::function<void(handler &)>>,
381+
event>
382+
submit(
379383
T CGF, queue &SecondaryQueue,
380384
const detail::code_location &CodeLoc = detail::code_location::current()) {
381385
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);

0 commit comments

Comments
 (0)