On Sat, 2017-02-11 at 03:12 +0100, Sandro Mani wrote:
> So rather than just removing -std=c++98 from the CMakeLists, the
> code must be changed to ensure the size of the enum is always the
> same regardless of the language standard one is using.

        Hi,
I would ideally use something like the attached change, but it has also
caveats. 

It lets me compile the test example with any standard, even with c++98,
while keeping the PoDoFo built with the default standard for the
compiler, but as the enum is defined in a public header, then when I
use lower-than c++11 (more precisely, when my compilation doesn't have
required standard version, but PoDoFo had been built with new-enough
C++ standard), the I get a warning from gcc:

   src/base/PdfCompilerCompat.h:202:29: warning: scoped enums only
   available with -std=c++11 or -std=gnu++11
     #define PODOFO_ENUM_UINT8 : uint8_t

Thus it can make, theoretically, a trouble. I do not see any good
solution for this, maybe only revert this change (r1810) all together
and change PdfVariant to not hold
   EPdfDataType m_eDataType;
but
   pdf_int8 m_eDataType;
instead, which would require some other internal changes possibly. I
would not change the public API otherwise, the functions would still
use the enum.

Opinions?
        Bye,
        zyx

-- 
http://www.litePDF.cz                                 i...@litepdf.cz
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 1822)
+++ CMakeLists.txt	(working copy)
@@ -22,6 +22,7 @@ SET(PODOFO_LIBVERSION "${PODOFO_SOVERSIO
 #
 INCLUDE(CheckIncludeFile)
 INCLUDE(CheckLibraryExists)
+INCLUDE(CheckCXXSourceCompiles)
 INCLUDE(TestBigEndian)
 INCLUDE(CheckTypeSize)
 
@@ -296,9 +297,9 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
         SET(PODOFO_USE_VISIBILITY ${PODOFO_HAVE_GCC4})
     ENDIF(NOT DEFINED PODOFO_USE_VISIBILITY)
 
-    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98")
+    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
 
-    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Woverloaded-virtual -Wswitch-enum -Wcast-qual -Wwrite-strings -Wredundant-decls -Wreorder")
+    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Woverloaded-virtual -Wswitch-enum -Wcast-qual -Wwrite-strings -Wredundant-decls -Wreorder -Wno-deprecated-declarations")
 
     #
     # Note that we do not need debug definitions here. Set
@@ -442,6 +443,16 @@ ENDIF(LUA_FOUND)
 ENDIF(NOT PODOFO_BUILD_LIB_ONLY)
 
 
+CHECK_CXX_SOURCE_COMPILES("
+		// Visual C++ 2015 (_MSC_VER 1900) still uses __cplusplus = 199711 so, we need both tests
+		// this shrinks enum types from sizeof(int) to sizeof(char) which creates significant
+		// space savings on PdfObject / PdfVariant
+		#if (defined(_MSC_VER) && _MSC_VER < 1900) || (!defined(_MSC_VER) && __cplusplus < 201103)
+			#error \"Cannot use uint8_t enums\"
+		#endif
+		int main(void) { return 0; }" PODOFO_HAVE_ENUM_UINT8)
+
+
 # Check if we should build a multithreaded version of PoDoFo
 IF(DEFINED PODOFO_NO_MULTITHREAD)
   MESSAGE("Building non multithreaded version of PoDoFo.")
Index: podofo_config.h.in
===================================================================
--- podofo_config.h.in	(revision 1822)
+++ podofo_config.h.in	(working copy)
@@ -14,6 +14,7 @@
 
 /* PoDoFo configuration options */
 #cmakedefine PODOFO_MULTI_THREAD
+#cmakedefine PODOFO_HAVE_ENUM_UINT8
 
 /* somewhat platform-specific headers */
 #cmakedefine PODOFO_HAVE_STRINGS_H 1
@@ -46,6 +47,7 @@
 /* Features */
 #cmakedefine PODOFO_NO_FONTMANAGER
 
+
 /* Libraries */
 #cmakedefine PODOFO_HAVE_JPEG_LIB
 #cmakedefine PODOFO_HAVE_PNG_LIB
Index: src/base/PdfCompilerCompat.h
===================================================================
--- src/base/PdfCompilerCompat.h	(revision 1822)
+++ src/base/PdfCompilerCompat.h	(working copy)
@@ -198,13 +198,10 @@ namespace PoDoFo {
 
 #endif // defined(_WIN32)
 
-// Visual C++ 2015 (_MSC_VER 1900) still uses __cplusplus = 199711 so, we need both tests
-// this shrinks enum types from sizeof(int) to sizeof(char) which creates significant
-// space savings on PdfObject / PdfVariant
-#if (defined(_MSC_VER) && _MSC_VER < 1900) || (!defined(_MSC_VER) &&  __cplusplus < 201103)
-#define PODOFO_ENUM_UINT8
-#else 
+#ifdef PODOFO_HAVE_ENUM_UINT8
 #define PODOFO_ENUM_UINT8	: uint8_t
+#else 
+#define PODOFO_ENUM_UINT8
 #endif 
 
 
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to