Tests/CompileFeatures: Cover c_std_## and cxx_std_## meta-features

This commit is contained in:
Brad King
2024-04-02 16:06:53 -04:00
parent 58cd9ee03c
commit c37e279014
12 changed files with 58 additions and 0 deletions

View File

@@ -6,6 +6,18 @@ project(CompileFeatures)
set(ext_C c)
set(ext_CXX cpp)
set(std_C 90 99 11 17 23)
set(std_CXX 98 11 14 17 20 23)
foreach(lang C CXX)
foreach(std IN LISTS std_${lang})
string(TOLOWER "${lang}_std_${std}" feature)
if(CMAKE_${lang}${std}_STANDARD_COMPILE_OPTION)
add_library(test_${feature} OBJECT ${feature}.${ext_${lang}})
target_compile_features(test_${feature} PRIVATE ${feature})
endif()
endforeach()
endforeach()
macro(run_test feature lang)
if (${feature} IN_LIST CMAKE_${lang}_COMPILE_FEATURES)

View File

@@ -0,0 +1,5 @@
#include "c_std.h"
#if defined(C_STD) && C_STD <= C_STD_99 && \
!(defined(__SUNPRO_C) && __SUNPRO_C < 0x5140 && C_STD == C_STD_99)
# error "c_std_11 not honored"
#endif

View File

@@ -0,0 +1,4 @@
#include "c_std.h"
#if defined(C_STD) && C_STD <= C_STD_11
# error "c_std_17 not honored"
#endif

View File

@@ -0,0 +1,6 @@
#include "c_std.h"
#if defined(C_STD) && C_STD <= C_STD_17 && \
!(C_STD == C_STD_17 && defined(__apple_build_version__) && \
defined(__clang_major__) && __clang_major__ < 14)
# error "c_std_23 not honored"
#endif

View File

View File

@@ -0,0 +1,4 @@
#include "c_std.h"
#if defined(C_STD) && C_STD < C_STD_99
# error "c_std_99 not honored"
#endif

View File

@@ -0,0 +1,6 @@
#include "cxx_std.h"
#if defined(CXX_STD) && CXX_STD < CXX_STD_11 && \
!(CXX_STD == CXX_STD_98 && \
(defined(__IBMCPP__) && defined(_AIX) && __IBMCPP__ == 1610))
# error "cxx_std_11 not honored"
#endif

View File

@@ -0,0 +1,9 @@
#include "cxx_std.h"
#if defined(CXX_STD) && CXX_STD <= CXX_STD_11 && \
!(CXX_STD == CXX_STD_11 && \
((defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 4 && \
__GNUC_MINOR__ <= 8 && !defined(__clang__) && \
!defined(__INTEL_COMPILER) && !defined(__PGI)) || \
(defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5150)))
# error "cxx_std_14 not honored"
#endif

View File

@@ -0,0 +1,4 @@
#include "cxx_std.h"
#if defined(CXX_STD) && CXX_STD <= CXX_STD_14
# error "cxx_std_17 not honored"
#endif

View File

@@ -0,0 +1,4 @@
#include "cxx_std.h"
#if defined(CXX_STD) && CXX_STD <= CXX_STD_17
# error "cxx_std_20 not honored"
#endif

View File

@@ -0,0 +1,4 @@
#include "cxx_std.h"
#if defined(CXX_STD) && CXX_STD <= CXX_STD_20
# error "cxx_std_23 not honored"
#endif

View File