blob: 68d8ab908d43af25b5cfbd7b0850758b4f641d59 [file] [log] [blame]
Ben Clayton77c89ff2020-01-08 19:10:14 +00001// Copyright 2020 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#if defined(_MSVC_LANG)
16# define CPP_VERSION _MSVC_LANG
17#elif defined(__cplusplus)
18// Note: This must come after checking for _MSVC_LANG.
19// See https://developercommunity.visualstudio.com/content/problem/139261/msvc-incorrectly-defines-cplusplus.html
20# define CPP_VERSION __cplusplus
21#endif
22
23#if !defined(CPP_VERSION) || CPP_VERSION <= 1
24# error "Unable to identify C++ language version"
25#endif
26
Nicolas Capensea1fde12020-07-29 11:58:52 -040027// The template and unused function below verifies the compiler is using at least
Nicolas Capensb3e5c442021-01-20 06:16:24 +000028// C++17. It will print an error message containing the actual C++ version if
29// the version is < 17.
Ben Clayton77c89ff2020-01-08 19:10:14 +000030
31namespace {
32
33template<int version>
34class cpp
35{
Nicolas Capensb3e5c442021-01-20 06:16:24 +000036 static_assert(version >= 2017, "SwiftShader requires at least C++17");
Ben Clayton77c89ff2020-01-08 19:10:14 +000037};
38
39void check_cpp_version()
40{
41 cpp<CPP_VERSION / 100>();
Nicolas Capensea1fde12020-07-29 11:58:52 -040042 (void)&check_cpp_version; // Unused reference to avoid unreferenced function warning.
Ben Clayton77c89ff2020-01-08 19:10:14 +000043}
44
45} // namespace