Browse Source

Intel: Fix detection of C++ 14/17 modes on Linux/macOS

The Intel Classic C++ compiler is based on EDG.  It does not always
define `__cplusplus` correctly, but does define feature macros that we
can use to distinguish these modes.
Brad King 1 year ago
parent
commit
863cde8c19
2 changed files with 16 additions and 0 deletions
  1. 8 0
      Modules/CMakeCXXCompilerId.cpp.in
  2. 8 0
      Tests/CompileFeatures/default_dialect.cpp

+ 8 - 0
Modules/CMakeCXXCompilerId.cpp.in

@@ -58,6 +58,14 @@ char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
 #  endif
 #elif defined(_MSC_VER) && defined(_MSVC_LANG)
 #  define CXX_STD _MSVC_LANG
+#elif defined(__INTEL_COMPILER)
+#  if __cplusplus == CXX_STD_11 && defined(__cpp_namespace_attributes)
+#    define CXX_STD CXX_STD_17
+#  elif __cplusplus == CXX_STD_11 && defined(__cpp_aggregate_nsdmi)
+#    define CXX_STD CXX_STD_14
+#  else
+#    define CXX_STD __cplusplus
+#  endif
 #else
 #  define CXX_STD __cplusplus
 #endif

+ 8 - 0
Tests/CompileFeatures/default_dialect.cpp

@@ -27,6 +27,14 @@ struct Outputter;
 #  endif
 #elif defined(_MSC_VER) && defined(_MSVC_LANG)
 #  define CXX_STD _MSVC_LANG
+#elif defined(__INTEL_COMPILER)
+#  if __cplusplus == CXX_STD_11 && defined(__cpp_namespace_attributes)
+#    define CXX_STD CXX_STD_17
+#  elif __cplusplus == CXX_STD_11 && defined(__cpp_aggregate_nsdmi)
+#    define CXX_STD CXX_STD_14
+#  else
+#    define CXX_STD __cplusplus
+#  endif
 #else
 #  define CXX_STD __cplusplus
 #endif