From ef318d54237bab83edd372fd66a2c45965224a3a Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 27 Jul 2015 16:01:55 -0400 Subject: [PATCH] Fixed compiler errors on Apple due to cross product of {C++03,C++11} x {libc++, libstdc++}. It included bringing in the correct in , and then only including when was needed. --- cryptlib.cpp | 4 ++-- datatest.cpp | 2 +- default.cpp | 3 ++- filters.cpp | 4 +--- misc.h | 6 +----- pubkey.h | 3 +-- stdcpp.h | 41 +++++++++++++++++++++++++++++++---------- validat1.cpp | 2 +- 8 files changed, 40 insertions(+), 25 deletions(-) diff --git a/cryptlib.cpp b/cryptlib.cpp index 3508fb37..c6c36510 100644 --- a/cryptlib.cpp +++ b/cryptlib.cpp @@ -6,6 +6,8 @@ #include "cryptlib.h" #include "misc.h" +#include "stdcpp.h" +#include "smartptr.h" #include "filters.h" #include "algparam.h" #include "fips140.h" @@ -15,8 +17,6 @@ #include "osrng.h" #include "trap.h" -#include - #if GCC_DIAGNOSTIC_AWARE # pragma GCC diagnostic ignored "-Wunused-value" # pragma GCC diagnostic ignored "-Wunused-variable" diff --git a/datatest.cpp b/datatest.cpp index 57b5cc05..63675007 100644 --- a/datatest.cpp +++ b/datatest.cpp @@ -8,8 +8,8 @@ #include "queue.h" #include "validate.h" #include "trap.h" + #include -#include USING_NAMESPACE(CryptoPP) USING_NAMESPACE(std) diff --git a/default.cpp b/default.cpp index 900ffcde..94e866f5 100644 --- a/default.cpp +++ b/default.cpp @@ -2,9 +2,10 @@ #include "pch.h" #include "default.h" +#include "stdcpp.h" #include "queue.h" + #include -#include #if GCC_DIAGNOSTIC_AWARE # pragma GCC diagnostic ignored "-Wunused-value" diff --git a/filters.cpp b/filters.cpp index 20fb1cc1..2b9faea7 100644 --- a/filters.cpp +++ b/filters.cpp @@ -8,11 +8,9 @@ #include "mqueue.h" #include "fltrimpl.h" #include "argnames.h" +#include "stdcpp.h" #include "trap.h" -#include -#include - #if GCC_DIAGNOSTIC_AWARE # pragma GCC diagnostic ignored "-Wunused-value" # pragma GCC diagnostic ignored "-Wunused-variable" diff --git a/misc.h b/misc.h index c3b260e0..30e080b5 100644 --- a/misc.h +++ b/misc.h @@ -3,13 +3,9 @@ #include "cryptlib.h" #include "smartptr.h" +#include "stdcpp.h" #include "trap.h" -#include // for memcpy and memmove -#include // for size_t when -stdlib=libc++ -#include // for std::streamsize -#include // for std::numeric_limits - #ifdef _MSC_VER #if _MSC_VER >= 1400 // VC2005 workaround: disable declarations that conflict with winnt.h diff --git a/pubkey.h b/pubkey.h index 224c51fa..98435c31 100644 --- a/pubkey.h +++ b/pubkey.h @@ -37,10 +37,9 @@ #include "eprecomp.h" #include "fips140.h" #include "argnames.h" +#include "stdcpp.h" #include "trap.h" -#include - // VC60 workaround: this macro is defined in shlobj.h and conflicts with a template parameter used in this file #undef INTERFACE diff --git a/stdcpp.h b/stdcpp.h index 619cc035..bede8d8d 100644 --- a/stdcpp.h +++ b/stdcpp.h @@ -11,17 +11,31 @@ #include #include #include -#include + +// http://marshall.calepin.co/c-and-xcode-46.html. LLVM places unique_ptr in std:: when using +// using -stdlib=libc++ (and not std::tr1::) regardless of C++03/C++11. We detect can detect +// it with _LIBCPP_VERSION, but its not accurate because Apple's built-in Clang behaves +// differently than a LLVM downloaded and compiled CLang. So we fall back to Clang's +// __has_include (http://clang.llvm.org/docs/LanguageExtensions.html#id3). +#if (__cplusplus >= 201103L) && !defined(__clang__) +# include +#elif defined(__clang__) +# if (__has_include()) +# include +# endif +#elif (__cplusplus < 201103L) +# include +#else +# include +#endif + +#include +#include #include #include #include #include -#include -#include - -#if !defined(_NDEBUG) && !defined(NDEBUG) -# include -#endif +#include #ifdef CRYPTOPP_INCLUDE_VECTOR_CC // workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 @@ -29,10 +43,17 @@ #endif // for alloca -#ifdef __sun +// #ifdef __sun +// #include +// #elif defined(__MINGW32__) || defined(__BORLANDC__) +// #include +// #endif + +// Rijdael uses alloca. Just include it for everyone.... #include -#elif defined(__MINGW32__) || defined(__BORLANDC__) -#include + +#if defined(__MINGW32__) || defined(__BORLANDC__) +# include #endif #ifdef _MSC_VER diff --git a/validat1.cpp b/validat1.cpp index 6ae85cab..15d5d442 100644 --- a/validat1.cpp +++ b/validat1.cpp @@ -3,6 +3,7 @@ #include "pch.h" #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 +#include "stdcpp.h" #include "files.h" #include "misc.h" #include "hex.h" @@ -39,7 +40,6 @@ #include "trap.h" #include -#include #include #include