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