Skip to content

Commit 3b6799a

Browse files
[SYCL] Prevent implicit conversion from device to queue. (#1292)
Signed-off-by: Elizabeth Andrews <[email protected]>
1 parent 52a63fa commit 3b6799a

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

sycl/include/CL/sycl/queue.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class queue {
7070
///
7171
/// \param SyclDevice is an instance of SYCL device.
7272
/// \param PropList is a list of properties for queue construction.
73-
queue(const device &SyclDevice, const property_list &PropList = {})
73+
explicit queue(const device &SyclDevice, const property_list &PropList = {})
7474
: queue(SyclDevice, async_handler{}, PropList) {}
7575

7676
/// Constructs a SYCL queue instance with an async_handler using the device
@@ -79,8 +79,8 @@ class queue {
7979
/// \param SyclDevice is an instance of SYCL device.
8080
/// \param AsyncHandler is a SYCL asynchronous exception handler.
8181
/// \param PropList is a list of properties for queue construction.
82-
queue(const device &SyclDevice, const async_handler &AsyncHandler,
83-
const property_list &PropList = {});
82+
explicit queue(const device &SyclDevice, const async_handler &AsyncHandler,
83+
const property_list &PropList = {});
8484

8585
/// Constructs a SYCL queue instance that is associated with the context
8686
/// provided, using the device returned by the device selector.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clangxx -fsyntax-only -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning
2+
//==-- implicit_conversion_error.cpp - Unintended implicit conversion check --==//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===-----------------------------------------------------------------------===//
9+
#include <CL/sycl.hpp>
10+
11+
int main() {
12+
cl::sycl::queue q;
13+
cl::sycl::context cxt = q.get_context();
14+
cl::sycl::device dev = q.get_device();
15+
16+
cl::sycl::context cxt2{dev};
17+
cl::sycl::context cxt3 = dev; // expected-error {{no viable conversion from 'cl::sycl::device' to 'cl::sycl::context'}}
18+
19+
cl::sycl::queue q2{dev};
20+
cl::sycl::queue q3 = dev; // expected-error {{no viable conversion from 'cl::sycl::device' to 'cl::sycl::queue'}}
21+
}

0 commit comments

Comments
 (0)