changeset 3728:0b3aacdf77f5

Fixed C++03 detection support for Visual C++ compilers
author Benjamin Golinvaux <bgo@osimis.io>
date Sun, 08 Mar 2020 19:51:22 +0100
parents ae0e3fd609df
children 982c24a70dfd
files Core/Compatibility.h
diffstat 1 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Compatibility.h	Wed Mar 04 10:00:42 2020 +0100
+++ b/Core/Compatibility.h	Sun Mar 08 19:51:22 2020 +0100
@@ -33,14 +33,27 @@
 
 #pragma once
 
-// __cplusplus cannot be used in Visual C++ versions older than 1914
-#if (defined _MSC_VER) && (_MSC_VER < 1914)
-#  if _MSC_VER < 1900
+//#define Orthanc_Compatibility_h_STR2(x) #x
+//#define Orthanc_Compatibility_h_STR1(x) Orthanc_Compatibility_h_STR2(x)
+
+//#pragma message("__cplusplus = " Orthanc_Compatibility_h_STR1(__cplusplus))
+
+#if (defined _MSC_VER)
+//#  pragma message("_MSC_VER = " Orthanc_Compatibility_h_STR1(_MSC_VER))
+// The __cplusplus macro cannot be used in Visual C++ < 1914 (VC++ 15.7)
+// However, even in recent versions, __cplusplus will only be correct (that is,
+// correctly defines the supported C++ version) if a special flag is passed to
+// the compiler ("/Zc:__cplusplus")
+// To make this header more robust, we use the _MSVC_LANG equivalent macro.
+#  if (defined _MSVC_LANG) && (_MSVC_LANG >= 201103L)
+#    define ORTHANC_Cxx03_DETECTED 0
+#  else
 #    define ORTHANC_Cxx03_DETECTED 1
-#  else
-#    define ORTHANC_Cxx03_DETECTED 0
 #  endif
 #else
+// of _MSC_VER is not defined, we assume __cplusplus is correctly defined
+// if __cplusplus is not defined (very old compilers??), then the following
+// test will compare 0 < 201103L and will be true --> safe.
 #  if __cplusplus < 201103L
 #    define ORTHANC_Cxx03_DETECTED 1
 #  else
@@ -48,8 +61,9 @@
 #  endif
 #endif
 
+#if ORTHANC_Cxx03_DETECTED == 1
+//#pragma message("C++ 11 support is not present.")
 
-#if ORTHANC_Cxx03_DETECTED == 1
 /**
  * "std::unique_ptr" was introduced in C++11, and "std::auto_ptr" was
  * removed in C++17. We emulate "std::auto_ptr" using boost: "The
@@ -78,5 +92,7 @@
     }      
   };
 }
-
+#else
+//# pragma message("C++ 11 support is present.")
+# include <memory>
 #endif