Skip to content

[SYCL] Emit an error on attempt to compile in less than C++17 mode #6678

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 4 commits into from
Sep 7, 2022
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
4 changes: 0 additions & 4 deletions sycl/doc/PreprocessorMacros.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ This file describes macros that have effect on SYCL compiler and run-time.
Disables all deprecation warnings in SYCL runtime headers, including SYCL
1.2.1 deprecations.

- **SYCL_DISABLE_CPP_VERSION_CHECK_WARNING**

Disables a message which warns about unsupported C++ version.

- **SYCL_FALLBACK_ASSERT**

Defining as non-zero enables the fallback assert feature even on devices
Expand Down
15 changes: 2 additions & 13 deletions sycl/include/sycl/detail/defines_elementary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,5 @@
#define __SYCL_WARNING(msg) __pragma(message(msg))
#endif // __GNUC__

#if !defined(SYCL_DISABLE_CPP_VERSION_CHECK_WARNING) && __cplusplus < 201703L

#if defined(_MSC_VER) && !defined(__clang__)
__SYCL_WARNING("DPCPP does not support C++ version earlier than C++17. Some "
"features might not be available.")
#else
// This is the only way to emit a warning from system headers using clang, it
// cannot be wrapped by a macro(__pragma warning doesn't work in system
// headers). The solution is borrowed from libcxx.
#warning: DPCPP does not support C++ version earlier than C++17. Some features might not be available.
#endif

#endif
static_assert(__cplusplus >= 201703L,
"DPCPP does not support C++ version earlier than C++17.");
5 changes: 3 additions & 2 deletions sycl/test/basic_tests/stdcpp_compat.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %clangxx -std=c++14 -fsycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify=expected,cxx14 %s -c -o %t.out
// RUN: %clangxx -std=c++14 -fsycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out -DSYCL_DISABLE_CPP_VERSION_CHECK_WARNING=1
// RUN: %clangxx -std=c++14 -fsycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify=cxx14,warning_extension,expected %s -c -o %t.out
// RUN: %clangxx -std=c++17 -fsycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out
// RUN: %clangxx -std=c++20 -fsycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out
Expand All @@ -10,13 +9,15 @@

#include <sycl/sycl.hpp>

// cxx14-warning@* {{DPCPP does not support C++ version earlier than C++17. Some features might not be available.}}
// clang-format off
// cxx14-error@* {{static assertion failed due to requirement '201402L >= 201703L'}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it works reliably - any attempt to use C++17 feature without macro guard would result in an extra error reported and the test would fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, the static_assert should fire very early as it's in the most basic header. But to make the test more reliable, probably, we could add -Xclang -verify-ignore-unexpected=error,note and -Xclang -ferror-limit=<Big number> options.

//
// The next warning is not emitted in device compilation for some reason
// warning_extension-warning@* 0-1 {{#warning is a C++2b extension}}
//
// The next warning is emitted for windows only
// expected-warning@* 0-1 {{Alignment of class vec is not in accordance with SYCL specification requirements, a limitation of the MSVC compiler(Error C2719).Requested alignment applied, limited at 64.}}
// clang-format on

class KernelName1;

Expand Down