Skip to content

[SYCL] Prevent implicit conversion from device to queue. #1292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sycl/include/CL/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class queue {
///
/// \param SyclDevice is an instance of SYCL device.
/// \param PropList is a list of properties for queue construction.
queue(const device &SyclDevice, const property_list &PropList = {})
explicit queue(const device &SyclDevice, const property_list &PropList = {})
: queue(SyclDevice, async_handler{}, PropList) {}

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

/// Constructs a SYCL queue instance that is associated with the context
/// provided, using the device returned by the device selector.
Expand Down
21 changes: 21 additions & 0 deletions sycl/test/basic_tests/implicit_conversion_error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %clangxx -fsyntax-only -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning
//==-- implicit_conversion_error.cpp - Unintended implicit conversion check --==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===-----------------------------------------------------------------------===//
#include <CL/sycl.hpp>

int main() {
cl::sycl::queue q;
cl::sycl::context cxt = q.get_context();
cl::sycl::device dev = q.get_device();

cl::sycl::context cxt2{dev};
cl::sycl::context cxt3 = dev; // expected-error {{no viable conversion from 'cl::sycl::device' to 'cl::sycl::context'}}

cl::sycl::queue q2{dev};
cl::sycl::queue q3 = dev; // expected-error {{no viable conversion from 'cl::sycl::device' to 'cl::sycl::queue'}}
}