Skip to content

Commit

Permalink
[SYCL] Prevent implicit conversion from device to queue. (#1292)
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
  • Loading branch information
elizabethandrews authored Mar 13, 2020
1 parent 52a63fa commit 3b6799a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
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'}}
}

0 comments on commit 3b6799a

Please sign in to comment.