GH #240: VERY strange error only when including Format.hinclude Alignment.h early

GH #240: VERY strange error only when including Format.h (include
Alignment.h early for consistency)
This commit is contained in:
Aleksandar Fabijanic
2013-07-22 01:10:36 -05:00
parent 20e1cf8821
commit a49f5da54b
4 changed files with 168 additions and 159 deletions

View File

@@ -54,21 +54,31 @@
#define Foundation_AlignOf_INCLUDED #define Foundation_AlignOf_INCLUDED
namespace Poco { #ifdef POCO_ENABLE_CPP11
template <typename T> #include <type_traits>
struct AlignmentCalcImpl #define POCO_HAVE_ALIGNMENT
{
#else
namespace Poco {
template <typename T>
struct AlignmentCalcImpl
{
char x; char x;
T t; T t;
private: private:
AlignmentCalcImpl() {} // Never instantiate. AlignmentCalcImpl() {} // Never instantiate.
}; };
template <typename T> template <typename T>
struct AlignOf struct AlignOf
/// A templated class that contains an enum value representing /// A templated class that contains an enum value representing
/// the alignment of the template argument. For example, /// the alignment of the template argument. For example,
/// AlignOf<int>::Alignment represents the alignment of type "int". The /// AlignOf<int>::Alignment represents the alignment of type "int". The
@@ -76,7 +86,7 @@ struct AlignOf
/// the "desired" alignment returned by GCC's __alignof__ (for example). Note /// the "desired" alignment returned by GCC's __alignof__ (for example). Note
/// that because the alignment is an enum value, it can be used as a /// that because the alignment is an enum value, it can be used as a
/// compile-time constant (e.g., for template instantiation). /// compile-time constant (e.g., for template instantiation).
{ {
enum enum
{ {
Alignment = static_cast<unsigned int>(sizeof(AlignmentCalcImpl<T>) - sizeof(T)) Alignment = static_cast<unsigned int>(sizeof(AlignmentCalcImpl<T>) - sizeof(T))
@@ -92,21 +102,21 @@ struct AlignOf
enum { Alignment_LessEqual_8Bytes = Alignment <= 8 ? 1 : 0 }; enum { Alignment_LessEqual_8Bytes = Alignment <= 8 ? 1 : 0 };
enum { Alignment_LessEqual_16Bytes = Alignment <= 16 ? 1 : 0 }; enum { Alignment_LessEqual_16Bytes = Alignment <= 16 ? 1 : 0 };
}; };
template <typename T> template <typename T>
inline unsigned alignOf() inline unsigned alignOf()
/// A templated function that returns the minimum alignment of /// A templated function that returns the minimum alignment of
/// of a type. This provides no extra functionality beyond the AlignOf /// of a type. This provides no extra functionality beyond the AlignOf
/// class besides some cosmetic cleanliness. Example usage: /// class besides some cosmetic cleanliness. Example usage:
/// alignOf<int>() returns the alignment of an int. /// alignOf<int>() returns the alignment of an int.
{ {
return AlignOf<T>::Alignment; return AlignOf<T>::Alignment;
} }
template <size_t Alignment> struct AlignedCharArrayImpl; template <size_t Alignment> struct AlignedCharArrayImpl;
/// Helper for building an aligned character array type. /// Helper for building an aligned character array type.
/// ///
/// This template is used to explicitly build up a collection of aligned /// This template is used to explicitly build up a collection of aligned
@@ -117,8 +127,8 @@ template <size_t Alignment> struct AlignedCharArrayImpl;
/// template parameters. /// template parameters.
// MSVC requires special handling here. // MSVC requires special handling here.
#ifndef _MSC_VER #ifndef _MSC_VER
#ifdef POCO_COMPILER_CLANG #ifdef POCO_COMPILER_CLANG
@@ -160,7 +170,7 @@ template <size_t Alignment> struct AlignedCharArrayImpl;
#undef POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT #undef POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
#endif // POCO_HAVE_ALIGNMENT #endif // POCO_HAVE_ALIGNMENT
#else // _MSC_VER #else // _MSC_VER
// We provide special variations of this template for the most common // We provide special variations of this template for the most common
// alignments because __declspec(align(...)) doesn't actually work when it is // alignments because __declspec(align(...)) doesn't actually work when it is
@@ -189,15 +199,15 @@ template <size_t Alignment> struct AlignedCharArrayImpl;
#undef POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT #undef POCO_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
#define POCO_HAVE_ALIGNMENT #define POCO_HAVE_ALIGNMENT
#endif // _MSC_VER #endif // _MSC_VER
// POCO_HAVE_ALIGNMENT will be defined on the pre-C++11 platforms/compilers where // POCO_HAVE_ALIGNMENT will be defined on the pre-C++11 platforms/compilers where
// it can be reliably determined and used. Uncomment the line below to explicitly // it can be reliably determined and used. Uncomment the line below to explicitly
// disable use of alignment even for those platforms. // disable use of alignment even for those platforms.
// #undef POCO_HAVE_ALIGNMENT // #undef POCO_HAVE_ALIGNMENT
#ifdef POCO_HAVE_ALIGNMENT #ifdef POCO_HAVE_ALIGNMENT
template <typename T1, typename T2 = char, typename T3 = char, typename T4 = char> template <typename T1, typename T2 = char, typename T3 = char, typename T4 = char>
union AlignedCharArrayUnion union AlignedCharArrayUnion
@@ -238,11 +248,14 @@ template <size_t Alignment> struct AlignedCharArrayImpl;
private: private:
Poco::AlignedCharArrayImpl<AlignOf<AlignerImpl>::Alignment> _nonceMember; Poco::AlignedCharArrayImpl<AlignOf<AlignerImpl>::Alignment> _nonceMember;
}; };
#endif // POCO_HAVE_ALIGNMENT #endif // POCO_HAVE_ALIGNMENT
} // namespace Poco } // namespace Poco
#endif // POCO_ENABLE_CPP11
#endif // Foundation_AlignOf_INCLUDED #endif // Foundation_AlignOf_INCLUDED

View File

@@ -40,13 +40,10 @@
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include "Poco/MetaProgramming.h" #include "Poco/MetaProgramming.h"
#include "Poco/Alignment.h"
#include <algorithm> #include <algorithm>
#include <typeinfo> #include <typeinfo>
#include <cstring> #include <cstring>
#ifdef POCO_ENABLE_CPP11
#include <type_traits>
#endif
namespace Poco { namespace Poco {

View File

@@ -129,6 +129,11 @@
#endif #endif
//
// Include alignment settings early
//
#include "Poco/Alignment.h"
// //
// Cleanup inconsistencies // Cleanup inconsistencies
// //

View File

@@ -46,12 +46,6 @@
#include "Poco/AutoPtr.h" #include "Poco/AutoPtr.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include <vector> #include <vector>
#ifdef POCO_ENABLE_CPP11
#include <type_traits>
#define POCO_HAVE_ALIGNMENT
#else
#include "Poco/Alignment.h"
#endif
namespace Poco { namespace Poco {