[llvm] [libsycl] Add sycl::exception constructors with context. (PR #220551)
Kseniya Tikhomirova via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 11 03:10:49 PDT 2026
https://github.com/KseniyaTikhomirova updated https://github.com/llvm/llvm-project/pull/220551
>From 7fb4916f5e59192f60d246484a7078db0214b4a6 Mon Sep 17 00:00:00 2001
From: "Tikhomirova, Kseniya" <kseniya.tikhomirova at intel.com>
Date: Tue, 1 Sep 2026 09:55:43 -0700
Subject: [PATCH 1/3] [libsycl] integrate context to sycl::exception
Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova at intel.com>
---
libsycl/include/sycl/__impl/context.hpp | 30 +++++
libsycl/include/sycl/__impl/exception.hpp | 63 +++++++++-
libsycl/src/exception.cpp | 18 ++-
libsycl/unittests/CMakeLists.txt | 1 +
libsycl/unittests/exception/CMakeLists.txt | 3 +
libsycl/unittests/exception/exception.cpp | 139 +++++++++++++++++++++
6 files changed, 244 insertions(+), 10 deletions(-)
create mode 100644 libsycl/unittests/exception/CMakeLists.txt
create mode 100644 libsycl/unittests/exception/exception.cpp
diff --git a/libsycl/include/sycl/__impl/context.hpp b/libsycl/include/sycl/__impl/context.hpp
index 3acc91fad9647..1140fe74f5c4a 100644
--- a/libsycl/include/sycl/__impl/context.hpp
+++ b/libsycl/include/sycl/__impl/context.hpp
@@ -16,7 +16,9 @@
#ifndef _LIBSYCL___IMPL_CONTEXT_HPP
#define _LIBSYCL___IMPL_CONTEXT_HPP
+#include <sycl/__impl/async_handler.hpp>
#include <sycl/__impl/backend.hpp>
+#include <sycl/__impl/exception.hpp>
#include <sycl/__impl/info/desc_base.hpp>
#include <sycl/__impl/detail/config.hpp>
@@ -84,6 +86,34 @@ class _LIBSYCL_EXPORT context {
friend sycl::detail::ImplUtils;
}; // class context
+// To avoid cross-dependency issues between sycl::context and sycl::exception,
+// definition of ctors that require a context parameter are moved to
+// context.hpp.
+inline exception::exception(context Ctx, std::error_code EC,
+ const std::string &WhatArg)
+ : exception(EC, std::make_shared<context>(Ctx), WhatArg.c_str()) {}
+
+inline exception::exception(context Ctx, std::error_code EC,
+ const char *WhatArg)
+ : exception(Ctx, EC, std::string(WhatArg)) {}
+
+inline exception::exception(context Ctx, std::error_code EC)
+ : exception(Ctx, EC, "") {}
+
+inline exception::exception(context Ctx, int EV,
+ const std::error_category &ECat,
+ const char *WhatArg)
+ : exception(Ctx, {EV, ECat}, std::string(WhatArg)) {}
+
+inline exception::exception(context Ctx, int EV,
+ const std::error_category &ECat,
+ const std::string &WhatArg)
+ : exception(Ctx, {EV, ECat}, WhatArg) {}
+
+inline exception::exception(context Ctx, int EV,
+ const std::error_category &ECat)
+ : exception(Ctx, EV, ECat, "") {}
+
_LIBSYCL_END_NAMESPACE_SYCL
template <>
diff --git a/libsycl/include/sycl/__impl/exception.hpp b/libsycl/include/sycl/__impl/exception.hpp
index bcc535cb0cf60..f69ad4c013ae3 100644
--- a/libsycl/include/sycl/__impl/exception.hpp
+++ b/libsycl/include/sycl/__impl/exception.hpp
@@ -26,7 +26,9 @@
_LIBSYCL_BEGIN_NAMESPACE_SYCL
+class context;
class exception_list;
+
namespace detail {
void addAsyncException(exception_list &, const std::exception_ptr &);
}
@@ -75,19 +77,61 @@ _LIBSYCL_EXPORT const std::error_category &sycl_category() noexcept;
/// default exception handler. Virtual inheritance is mandated by SYCL 2020.
class _LIBSYCL_EXPORT exception : public virtual std::exception {
public:
- exception(std::error_code, const char *);
- exception(std::error_code Ec, const std::string &Msg)
- : exception(Ec, Msg.c_str()) {}
+ /// Constructs a SYCL exception without an associated context.
+ ///
+ /// \param EC Error code identifying the SYCL error.
+ /// \param Msg Message describing the error condition.
+ exception(std::error_code EC, const char *Msg)
+ : exception(EC, nullptr, Msg) {}
+ /// \overload
+ exception(std::error_code EC, const std::string &Msg)
+ : exception(EC, Msg.c_str()) {}
+
+ /// \overload
exception(std::error_code EC) : exception(EC, "") {}
+
+ /// \overload
exception(int EV, const std::error_category &ECat, const std::string &WhatArg)
: exception(EV, ECat, WhatArg.c_str()) {}
+
+ /// \overload
exception(int EV, const std::error_category &ECat, const char *WhatArg)
: exception({EV, ECat}, WhatArg) {}
+
+ /// \overload
exception(int EV, const std::error_category &ECat)
: exception({EV, ECat}, "") {}
- virtual ~exception();
+ // To avoid cross-dependency issues between sycl::context and sycl::exception,
+ // definition of ctors that require a context parameter are moved to
+ // context.hpp.
+
+ /// Constructs a SYCL exception with an associated SYCL context.
+ ///
+ /// \param ctx SYCL context associated with the exception.
+ /// \param ec Error code identifying the SYCL error.
+ /// \param what_arg Message describing the error condition.
+ exception(context ctx, std::error_code ec, const std::string &what_arg);
+
+ /// \overload
+ exception(context ctx, std::error_code ec, const char *what_arg);
+
+ /// \overload
+ exception(context ctx, std::error_code ec);
+
+ /// \overload
+ exception(context ctx, int ev, const std::error_category &ecat,
+ const std::string &what_arg);
+
+ /// \overload
+ exception(context ctx, int ev, const std::error_category &ecat,
+ const char *what_arg);
+
+ /// \overload
+ exception(context ctx, int ev, const std::error_category &ecat);
+
+ virtual ~exception() = default;
/// Returns the error code stored inside the exception.
///
@@ -111,10 +155,19 @@ class _LIBSYCL_EXPORT exception : public virtual std::exception {
/// false if it does not.
bool has_context() const noexcept;
+ /// \return the SYCL context associated with this exception.
+ ///
+ /// \throws exception with sycl::errc::invalid if this exception does not
+ /// have an associated context (has_context() == false).
+ context get_context() const;
+
private:
+ exception(std::error_code Ec, std::shared_ptr<context> SharedPtrCtx,
+ const char *WhatArg);
// Exceptions must be noexcept copy constructible, so cannot use std::string
- // directly.
+ // or context directly.
std::shared_ptr<std::string> MMessage;
+ std::shared_ptr<context> MContext;
std::error_code MErrC = make_error_code(sycl::errc::invalid);
};
diff --git a/libsycl/src/exception.cpp b/libsycl/src/exception.cpp
index 0b69c2a217fdc..839f7c7a906da 100644
--- a/libsycl/src/exception.cpp
+++ b/libsycl/src/exception.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include <sycl/__impl/context.hpp>
#include <sycl/__impl/detail/config.hpp>
#include <sycl/__impl/exception.hpp>
@@ -30,10 +31,10 @@ std::error_code make_error_code(sycl::errc Err) noexcept {
}
// Exception methods implementation
-exception::exception(std::error_code EC, const char *Msg)
- : MMessage(std::make_shared<std::string>(Msg)), MErrC(EC) {}
-
-exception::~exception() {}
+exception::exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
+ const char *Msg)
+ : MMessage(std::make_shared<std::string>(Msg)), MContext(SharedPtrCtx),
+ MErrC(EC) {}
const std::error_code &exception::code() const noexcept { return MErrC; }
@@ -43,6 +44,13 @@ const std::error_category &exception::category() const noexcept {
const char *exception::what() const noexcept { return MMessage->c_str(); }
-bool exception::has_context() const noexcept { return false; }
+bool exception::has_context() const noexcept { return MContext != nullptr; }
+
+context exception::get_context() const {
+ if (!has_context())
+ throw exception(make_error_code(sycl::errc::invalid),
+ "Exception does not have an associated context.");
+ return *MContext;
+}
_LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/unittests/CMakeLists.txt b/libsycl/unittests/CMakeLists.txt
index 349818cedb597..5e545de8278e7 100644
--- a/libsycl/unittests/CMakeLists.txt
+++ b/libsycl/unittests/CMakeLists.txt
@@ -10,6 +10,7 @@ set_target_properties(LibsyclUnitTests PROPERTIES FOLDER "libsycl/Tests/Unit")
add_subdirectory(mock)
add_subdirectory(device_selector)
add_subdirectory(event)
+add_subdirectory(exception)
add_subdirectory(platform)
add_subdirectory(program_manager)
add_subdirectory(queue)
diff --git a/libsycl/unittests/exception/CMakeLists.txt b/libsycl/unittests/exception/CMakeLists.txt
new file mode 100644
index 0000000000000..dcf405f129fe9
--- /dev/null
+++ b/libsycl/unittests/exception/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_sycl_unittest(ExceptionTests
+ exception.cpp
+)
diff --git a/libsycl/unittests/exception/exception.cpp b/libsycl/unittests/exception/exception.cpp
new file mode 100644
index 0000000000000..1cd8b5eec8fae
--- /dev/null
+++ b/libsycl/unittests/exception/exception.cpp
@@ -0,0 +1,139 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <sycl/sycl.hpp>
+
+#include <gtest/gtest.h>
+
+#include <cstring>
+#include <string>
+#include <vector>
+
+using namespace sycl;
+
+TEST(ExceptionTest, ConstructorsWithoutContext) {
+ std::string Msg = "custom error message";
+ const char *MsgCStr = "c-string error message";
+
+ exception Ex1(make_error_code(errc::runtime), Msg);
+ EXPECT_EQ(Ex1.code(), make_error_code(errc::runtime));
+ EXPECT_EQ(Ex1.category(), sycl_category());
+ EXPECT_STREQ(Ex1.what(), Msg.c_str());
+ EXPECT_FALSE(Ex1.has_context());
+ EXPECT_THROW(
+ {
+ try {
+ Ex1.get_context();
+ } catch (const sycl::exception &E) {
+ EXPECT_EQ(E.code(), make_error_code(errc::invalid));
+ throw;
+ }
+ },
+ sycl::exception);
+
+ exception Ex2(make_error_code(errc::kernel), MsgCStr);
+ EXPECT_EQ(Ex2.code(), make_error_code(errc::kernel));
+ EXPECT_STREQ(Ex2.what(), MsgCStr);
+ EXPECT_FALSE(Ex2.has_context());
+
+ exception Ex3(make_error_code(errc::accessor));
+ EXPECT_EQ(Ex3.code(), make_error_code(errc::accessor));
+ EXPECT_STREQ(Ex3.what(), "");
+ EXPECT_FALSE(Ex3.has_context());
+
+ exception Ex4(static_cast<int>(errc::nd_range), sycl_category(), Msg);
+ EXPECT_EQ(Ex4.code(), make_error_code(errc::nd_range));
+ EXPECT_STREQ(Ex4.what(), Msg.c_str());
+ EXPECT_FALSE(Ex4.has_context());
+
+ exception Ex5(static_cast<int>(errc::event), sycl_category(), MsgCStr);
+ EXPECT_EQ(Ex5.code(), make_error_code(errc::event));
+ EXPECT_STREQ(Ex5.what(), MsgCStr);
+ EXPECT_FALSE(Ex5.has_context());
+
+ exception Ex6(static_cast<int>(errc::kernel_argument), sycl_category());
+ EXPECT_EQ(Ex6.code(), make_error_code(errc::kernel_argument));
+ EXPECT_STREQ(Ex6.what(), "");
+ EXPECT_FALSE(Ex6.has_context());
+}
+
+TEST(ExceptionTest, ConstructorsWithContext) {
+ auto Platforms = sycl::platform::get_platforms();
+ ASSERT_FALSE(Platforms.empty());
+ context Ctx = Platforms[0].khr_get_default_context();
+
+ std::string Msg = "context error message";
+ const char *MsgCStr = "context c-string error message";
+
+ exception Ex1(Ctx, make_error_code(errc::build), Msg);
+ EXPECT_EQ(Ex1.code(), make_error_code(errc::build));
+ EXPECT_EQ(Ex1.category(), sycl_category());
+ EXPECT_STREQ(Ex1.what(), Msg.c_str());
+ EXPECT_TRUE(Ex1.has_context());
+ EXPECT_NO_THROW({ EXPECT_EQ(Ex1.get_context(), Ctx); });
+
+ exception Ex2(Ctx, make_error_code(errc::invalid), MsgCStr);
+ EXPECT_EQ(Ex2.code(), make_error_code(errc::invalid));
+ EXPECT_STREQ(Ex2.what(), MsgCStr);
+ EXPECT_TRUE(Ex2.has_context());
+ EXPECT_EQ(Ex2.get_context(), Ctx);
+
+ exception Ex3(Ctx, make_error_code(errc::memory_allocation));
+ EXPECT_EQ(Ex3.code(), make_error_code(errc::memory_allocation));
+ EXPECT_STREQ(Ex3.what(), "");
+ EXPECT_TRUE(Ex3.has_context());
+ EXPECT_EQ(Ex3.get_context(), Ctx);
+
+ exception Ex4(Ctx, static_cast<int>(errc::platform), sycl_category(), Msg);
+ EXPECT_EQ(Ex4.code(), make_error_code(errc::platform));
+ EXPECT_STREQ(Ex4.what(), Msg.c_str());
+ EXPECT_TRUE(Ex4.has_context());
+ EXPECT_EQ(Ex4.get_context(), Ctx);
+
+ exception Ex5(Ctx, static_cast<int>(errc::profiling), sycl_category(),
+ MsgCStr);
+ EXPECT_EQ(Ex5.code(), make_error_code(errc::profiling));
+ EXPECT_STREQ(Ex5.what(), MsgCStr);
+ EXPECT_TRUE(Ex5.has_context());
+ EXPECT_EQ(Ex5.get_context(), Ctx);
+
+ exception Ex6(Ctx, static_cast<int>(errc::feature_not_supported),
+ sycl_category());
+ EXPECT_EQ(Ex6.code(), make_error_code(errc::feature_not_supported));
+ EXPECT_STREQ(Ex6.what(), "");
+ EXPECT_TRUE(Ex6.has_context());
+ EXPECT_EQ(Ex6.get_context(), Ctx);
+}
+
+TEST(ExceptionTest, CopyAndMoveSemantics) {
+ static_assert(std::is_nothrow_copy_constructible_v<exception>,
+ "sycl::exception must be nothrow copy constructible");
+
+ constexpr char Message[] = "original exception";
+
+ auto Platforms = sycl::platform::get_platforms();
+ ASSERT_FALSE(Platforms.empty());
+ context Ctx = Platforms[0].khr_get_default_context();
+
+ exception Orig(Ctx, make_error_code(errc::runtime), Message);
+ EXPECT_TRUE(Orig.has_context());
+
+ exception Copy = Orig;
+ EXPECT_TRUE(Copy.has_context());
+ EXPECT_EQ(Copy.get_context(), Ctx);
+ EXPECT_EQ(Copy.code(), make_error_code(errc::runtime));
+ EXPECT_STREQ(Copy.what(), Message);
+
+ exception Assigned(make_error_code(errc::invalid));
+ EXPECT_FALSE(Assigned.has_context());
+ Assigned = Copy;
+ EXPECT_TRUE(Assigned.has_context());
+ EXPECT_EQ(Assigned.get_context(), Ctx);
+ EXPECT_EQ(Assigned.code(), make_error_code(errc::runtime));
+ EXPECT_STREQ(Assigned.what(), Message);
+}
>From e6522f759e66146b03682f2eb86ad08b8c9ec935 Mon Sep 17 00:00:00 2001
From: "Tikhomirova, Kseniya" <kseniya.tikhomirova at intel.com>
Date: Tue, 8 Sep 2026 07:48:23 -0700
Subject: [PATCH 2/3] fix code style
Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova at intel.com>
---
libsycl/include/sycl/__impl/context.hpp | 48 +++++++++++------------
libsycl/include/sycl/__impl/exception.hpp | 33 ++++++++--------
libsycl/src/exception.cpp | 8 ++--
3 files changed, 45 insertions(+), 44 deletions(-)
diff --git a/libsycl/include/sycl/__impl/context.hpp b/libsycl/include/sycl/__impl/context.hpp
index 1140fe74f5c4a..e37ea5b63ff72 100644
--- a/libsycl/include/sycl/__impl/context.hpp
+++ b/libsycl/include/sycl/__impl/context.hpp
@@ -89,30 +89,30 @@ class _LIBSYCL_EXPORT context {
// To avoid cross-dependency issues between sycl::context and sycl::exception,
// definition of ctors that require a context parameter are moved to
// context.hpp.
-inline exception::exception(context Ctx, std::error_code EC,
- const std::string &WhatArg)
- : exception(EC, std::make_shared<context>(Ctx), WhatArg.c_str()) {}
-
-inline exception::exception(context Ctx, std::error_code EC,
- const char *WhatArg)
- : exception(Ctx, EC, std::string(WhatArg)) {}
-
-inline exception::exception(context Ctx, std::error_code EC)
- : exception(Ctx, EC, "") {}
-
-inline exception::exception(context Ctx, int EV,
- const std::error_category &ECat,
- const char *WhatArg)
- : exception(Ctx, {EV, ECat}, std::string(WhatArg)) {}
-
-inline exception::exception(context Ctx, int EV,
- const std::error_category &ECat,
- const std::string &WhatArg)
- : exception(Ctx, {EV, ECat}, WhatArg) {}
-
-inline exception::exception(context Ctx, int EV,
- const std::error_category &ECat)
- : exception(Ctx, EV, ECat, "") {}
+inline exception::exception(context ctx, std::error_code ec,
+ const std::string &what_arg)
+ : exception(ec, std::make_shared<context>(ctx), what_arg.c_str()) {}
+
+inline exception::exception(context ctx, std::error_code ec,
+ const char *what_arg)
+ : exception(ctx, ec, std::string(what_arg)) {}
+
+inline exception::exception(context ctx, std::error_code ec)
+ : exception(ctx, ec, "") {}
+
+inline exception::exception(context ctx, int ev,
+ const std::error_category &ecat,
+ const char *what_arg)
+ : exception(ctx, {ev, ecat}, std::string(what_arg)) {}
+
+inline exception::exception(context ctx, int ev,
+ const std::error_category &ecat,
+ const std::string &what_arg)
+ : exception(ctx, {ev, ecat}, what_arg) {}
+
+inline exception::exception(context ctx, int ev,
+ const std::error_category &ecat)
+ : exception(ctx, ev, ecat, "") {}
_LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/include/sycl/__impl/exception.hpp b/libsycl/include/sycl/__impl/exception.hpp
index f69ad4c013ae3..34f190f57ff35 100644
--- a/libsycl/include/sycl/__impl/exception.hpp
+++ b/libsycl/include/sycl/__impl/exception.hpp
@@ -54,10 +54,10 @@ enum class errc : int {
/// Constructs an error code using sycl::errc and sycl_category().
///
-/// \param E SYCL 2020 error code.
+/// \param e SYCL 2020 error code.
///
/// \returns constructed error code.
-_LIBSYCL_EXPORT std::error_code make_error_code(sycl::errc E) noexcept;
+_LIBSYCL_EXPORT std::error_code make_error_code(sycl::errc e) noexcept;
/// Obtains a reference to the static error category object for SYCL errors.
///
@@ -79,29 +79,30 @@ class _LIBSYCL_EXPORT exception : public virtual std::exception {
public:
/// Constructs a SYCL exception without an associated context.
///
- /// \param EC Error code identifying the SYCL error.
- /// \param Msg Message describing the error condition.
- exception(std::error_code EC, const char *Msg)
- : exception(EC, nullptr, Msg) {}
+ /// \param ec Error code identifying the SYCL error.
+ /// \param what_arg Message describing the error condition.
+ exception(std::error_code ec, const char *what_arg)
+ : exception(ec, nullptr, what_arg) {}
/// \overload
- exception(std::error_code EC, const std::string &Msg)
- : exception(EC, Msg.c_str()) {}
+ exception(std::error_code ec, const std::string &what_arg)
+ : exception(ec, what_arg.c_str()) {}
/// \overload
- exception(std::error_code EC) : exception(EC, "") {}
+ exception(std::error_code ec) : exception(ec, "") {}
/// \overload
- exception(int EV, const std::error_category &ECat, const std::string &WhatArg)
- : exception(EV, ECat, WhatArg.c_str()) {}
+ exception(int ev, const std::error_category &ecat,
+ const std::string &what_arg)
+ : exception(ev, ecat, what_arg.c_str()) {}
/// \overload
- exception(int EV, const std::error_category &ECat, const char *WhatArg)
- : exception({EV, ECat}, WhatArg) {}
+ exception(int ev, const std::error_category &ecat, const char *what_arg)
+ : exception({ev, ecat}, what_arg) {}
/// \overload
- exception(int EV, const std::error_category &ECat)
- : exception({EV, ECat}, "") {}
+ exception(int ev, const std::error_category &ecat)
+ : exception({ev, ecat}, "") {}
// To avoid cross-dependency issues between sycl::context and sycl::exception,
// definition of ctors that require a context parameter are moved to
@@ -162,7 +163,7 @@ class _LIBSYCL_EXPORT exception : public virtual std::exception {
context get_context() const;
private:
- exception(std::error_code Ec, std::shared_ptr<context> SharedPtrCtx,
+ exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
const char *WhatArg);
// Exceptions must be noexcept copy constructible, so cannot use std::string
// or context directly.
diff --git a/libsycl/src/exception.cpp b/libsycl/src/exception.cpp
index 839f7c7a906da..2964aaaeecdda 100644
--- a/libsycl/src/exception.cpp
+++ b/libsycl/src/exception.cpp
@@ -26,14 +26,14 @@ const std::error_category &sycl_category() noexcept {
return SYCLCategoryObj;
}
-std::error_code make_error_code(sycl::errc Err) noexcept {
- return std::error_code(static_cast<int>(Err), sycl_category());
+std::error_code make_error_code(sycl::errc e) noexcept {
+ return std::error_code(static_cast<int>(e), sycl_category());
}
// Exception methods implementation
exception::exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
- const char *Msg)
- : MMessage(std::make_shared<std::string>(Msg)), MContext(SharedPtrCtx),
+ const char *WhatArg)
+ : MMessage(std::make_shared<std::string>(WhatArg)), MContext(SharedPtrCtx),
MErrC(EC) {}
const std::error_code &exception::code() const noexcept { return MErrC; }
>From 3bab3b2bbbb65d92cec4884d2d069c0f8d07dfc1 Mon Sep 17 00:00:00 2001
From: "Tikhomirova, Kseniya" <kseniya.tikhomirova at intel.com>
Date: Fri, 11 Sep 2026 03:10:32 -0700
Subject: [PATCH 3/3] fix dtor
Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova at intel.com>
---
libsycl/include/sycl/__impl/exception.hpp | 2 +-
libsycl/src/exception.cpp | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/libsycl/include/sycl/__impl/exception.hpp b/libsycl/include/sycl/__impl/exception.hpp
index 34f190f57ff35..c3c8ff32a1e05 100644
--- a/libsycl/include/sycl/__impl/exception.hpp
+++ b/libsycl/include/sycl/__impl/exception.hpp
@@ -132,7 +132,7 @@ class _LIBSYCL_EXPORT exception : public virtual std::exception {
/// \overload
exception(context ctx, int ev, const std::error_category &ecat);
- virtual ~exception() = default;
+ virtual ~exception();
/// Returns the error code stored inside the exception.
///
diff --git a/libsycl/src/exception.cpp b/libsycl/src/exception.cpp
index 2964aaaeecdda..4db4cff50f9f2 100644
--- a/libsycl/src/exception.cpp
+++ b/libsycl/src/exception.cpp
@@ -36,6 +36,8 @@ exception::exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
: MMessage(std::make_shared<std::string>(WhatArg)), MContext(SharedPtrCtx),
MErrC(EC) {}
+exception::~exception() = default;
+
const std::error_code &exception::code() const noexcept { return MErrC; }
const std::error_category &exception::category() const noexcept {
More information about the llvm-commits
mailing list