Ben Clayton | 77c89ff | 2020-01-08 19:10:14 +0000 | [diff] [blame] | 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 | |
Nicolas Capens | ea1fde1 | 2020-07-29 11:58:52 -0400 | [diff] [blame] | 27 | // The template and unused function below verifies the compiler is using at least |
Nicolas Capens | b3e5c44 | 2021-01-20 06:16:24 +0000 | [diff] [blame^] | 28 | // C++17. It will print an error message containing the actual C++ version if |
| 29 | // the version is < 17. |
Ben Clayton | 77c89ff | 2020-01-08 19:10:14 +0000 | [diff] [blame] | 30 | |
| 31 | namespace { |
| 32 | |
| 33 | template<int version> |
| 34 | class cpp |
| 35 | { |
Nicolas Capens | b3e5c44 | 2021-01-20 06:16:24 +0000 | [diff] [blame^] | 36 | static_assert(version >= 2017, "SwiftShader requires at least C++17"); |
Ben Clayton | 77c89ff | 2020-01-08 19:10:14 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | void check_cpp_version() |
| 40 | { |
| 41 | cpp<CPP_VERSION / 100>(); |
Nicolas Capens | ea1fde1 | 2020-07-29 11:58:52 -0400 | [diff] [blame] | 42 | (void)&check_cpp_version; // Unused reference to avoid unreferenced function warning. |
Ben Clayton | 77c89ff | 2020-01-08 19:10:14 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | } // namespace |