From c37e2790145d0b304f2072bee3d5206ecb12eafc Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 2 Apr 2024 16:06:53 -0400 Subject: Tests/CompileFeatures: Cover c_std_## and cxx_std_## meta-features --- Tests/CompileFeatures/CMakeLists.txt | 12 ++++++++++++ Tests/CompileFeatures/c_std_11.c | 5 +++++ Tests/CompileFeatures/c_std_17.c | 4 ++++ Tests/CompileFeatures/c_std_23.c | 6 ++++++ Tests/CompileFeatures/c_std_90.c | 0 Tests/CompileFeatures/c_std_99.c | 4 ++++ Tests/CompileFeatures/cxx_std_11.cpp | 6 ++++++ Tests/CompileFeatures/cxx_std_14.cpp | 9 +++++++++ Tests/CompileFeatures/cxx_std_17.cpp | 4 ++++ Tests/CompileFeatures/cxx_std_20.cpp | 4 ++++ Tests/CompileFeatures/cxx_std_23.cpp | 4 ++++ Tests/CompileFeatures/cxx_std_98.cpp | 0 12 files changed, 58 insertions(+) create mode 100644 Tests/CompileFeatures/c_std_11.c create mode 100644 Tests/CompileFeatures/c_std_17.c create mode 100644 Tests/CompileFeatures/c_std_23.c create mode 100644 Tests/CompileFeatures/c_std_90.c create mode 100644 Tests/CompileFeatures/c_std_99.c create mode 100644 Tests/CompileFeatures/cxx_std_11.cpp create mode 100644 Tests/CompileFeatures/cxx_std_14.cpp create mode 100644 Tests/CompileFeatures/cxx_std_17.cpp create mode 100644 Tests/CompileFeatures/cxx_std_20.cpp create mode 100644 Tests/CompileFeatures/cxx_std_23.cpp create mode 100644 Tests/CompileFeatures/cxx_std_98.cpp diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index d9bb447..844c33e 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -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) diff --git a/Tests/CompileFeatures/c_std_11.c b/Tests/CompileFeatures/c_std_11.c new file mode 100644 index 0000000..2938c17 --- /dev/null +++ b/Tests/CompileFeatures/c_std_11.c @@ -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 diff --git a/Tests/CompileFeatures/c_std_17.c b/Tests/CompileFeatures/c_std_17.c new file mode 100644 index 0000000..938cba4 --- /dev/null +++ b/Tests/CompileFeatures/c_std_17.c @@ -0,0 +1,4 @@ +#include "c_std.h" +#if defined(C_STD) && C_STD <= C_STD_11 +# error "c_std_17 not honored" +#endif diff --git a/Tests/CompileFeatures/c_std_23.c b/Tests/CompileFeatures/c_std_23.c new file mode 100644 index 0000000..6073b552 --- /dev/null +++ b/Tests/CompileFeatures/c_std_23.c @@ -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 diff --git a/Tests/CompileFeatures/c_std_90.c b/Tests/CompileFeatures/c_std_90.c new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CompileFeatures/c_std_99.c b/Tests/CompileFeatures/c_std_99.c new file mode 100644 index 0000000..20b6372 --- /dev/null +++ b/Tests/CompileFeatures/c_std_99.c @@ -0,0 +1,4 @@ +#include "c_std.h" +#if defined(C_STD) && C_STD < C_STD_99 +# error "c_std_99 not honored" +#endif diff --git a/Tests/CompileFeatures/cxx_std_11.cpp b/Tests/CompileFeatures/cxx_std_11.cpp new file mode 100644 index 0000000..aa85cdb --- /dev/null +++ b/Tests/CompileFeatures/cxx_std_11.cpp @@ -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 diff --git a/Tests/CompileFeatures/cxx_std_14.cpp b/Tests/CompileFeatures/cxx_std_14.cpp new file mode 100644 index 0000000..dabd2ee --- /dev/null +++ b/Tests/CompileFeatures/cxx_std_14.cpp @@ -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 diff --git a/Tests/CompileFeatures/cxx_std_17.cpp b/Tests/CompileFeatures/cxx_std_17.cpp new file mode 100644 index 0000000..3ca6bbe --- /dev/null +++ b/Tests/CompileFeatures/cxx_std_17.cpp @@ -0,0 +1,4 @@ +#include "cxx_std.h" +#if defined(CXX_STD) && CXX_STD <= CXX_STD_14 +# error "cxx_std_17 not honored" +#endif diff --git a/Tests/CompileFeatures/cxx_std_20.cpp b/Tests/CompileFeatures/cxx_std_20.cpp new file mode 100644 index 0000000..35f5ac1 --- /dev/null +++ b/Tests/CompileFeatures/cxx_std_20.cpp @@ -0,0 +1,4 @@ +#include "cxx_std.h" +#if defined(CXX_STD) && CXX_STD <= CXX_STD_17 +# error "cxx_std_20 not honored" +#endif diff --git a/Tests/CompileFeatures/cxx_std_23.cpp b/Tests/CompileFeatures/cxx_std_23.cpp new file mode 100644 index 0000000..020578d --- /dev/null +++ b/Tests/CompileFeatures/cxx_std_23.cpp @@ -0,0 +1,4 @@ +#include "cxx_std.h" +#if defined(CXX_STD) && CXX_STD <= CXX_STD_20 +# error "cxx_std_23 not honored" +#endif diff --git a/Tests/CompileFeatures/cxx_std_98.cpp b/Tests/CompileFeatures/cxx_std_98.cpp new file mode 100644 index 0000000..e69de29 -- cgit v0.12