blob: 5552ae5a237d42b2567af34b82b610378db9f526 [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
27// The template and dummy function below verifies the compiler is using at least
28// C++14. It will print an error message containing the actual C++ version if
29// the version is < 14.
30
31namespace {
32
33template<int version>
34class cpp
35{
36 static_assert(version >= 2014, "SwiftShader requires at least C++14");
37};
38
39void check_cpp_version()
40{
41 cpp<CPP_VERSION / 100>();
42 (void)&check_cpp_version; // dummy reference to avoid unreferenced function warning.
43}
44
45} // namespace