diff --git a/sycl/include/sycl/stl_wrappers/assert.h b/sycl/include/sycl/stl_wrappers/assert.h index 67395dc7095d6..8156eaa5edb3d 100644 --- a/sycl/include/sycl/stl_wrappers/assert.h +++ b/sycl/include/sycl/stl_wrappers/assert.h @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// // Must not be guarded. C++ standard says the macro assert is redefined -// according to the current state of NDEBUG each time that is +// according to the current state of NDEBUG each time that is // included. #if defined(__has_include_next) @@ -16,6 +16,7 @@ #include <../ucrt/assert.h> #endif +extern "C++" { #ifdef __SYCL_DEVICE_ONLY__ #include @@ -42,3 +43,4 @@ __devicelib_assert_fail(const char *, const char *, int32_t, const char *, #endif #endif #endif +} diff --git a/sycl/include/sycl/stl_wrappers/cassert b/sycl/include/sycl/stl_wrappers/cassert index f91cf8b632984..64eb839582652 100644 --- a/sycl/include/sycl/stl_wrappers/cassert +++ b/sycl/include/sycl/stl_wrappers/cassert @@ -16,6 +16,7 @@ #include <../include/cassert> #endif +extern "C++" { #ifdef __SYCL_DEVICE_ONLY__ #include @@ -42,3 +43,4 @@ __devicelib_assert_fail(const char *, const char *, int32_t, const char *, #endif #endif #endif +} diff --git a/sycl/test/basic_tests/assert_header_with_c_linkage.cpp b/sycl/test/basic_tests/assert_header_with_c_linkage.cpp new file mode 100644 index 0000000000000..c5a81d9730134 --- /dev/null +++ b/sycl/test/basic_tests/assert_header_with_c_linkage.cpp @@ -0,0 +1,19 @@ +// RUN: %clangxx -fsycl -DASSERT -fsyntax-only %s +// RUN: %clangxx -fsycl -DCASSERT -fsyntax-only %s + +// Verify that compilation works when assert.h/cassert is wrapped by a C linkage +// specification. + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(ASSERT) +#include +#elif defined(CASSERT) +#include +#endif + +#ifdef __cplusplus +} +#endif