Avoid using std::max_align_t in pre-C++11 mode
Always depend on the compiler to have a correct implementation of max_align_t in stddef.h and don't provide a fallback. For pre-C++11, require __STDCPP_NEW_ALIGNMENT__ in <new> as provided by clang in all standard modes. Adjust test cases to avoid testing or using max_align_t in pre-C++11 mode and also to better deal with alignof(max_align_t)>16. Document requirements of the alignment tests around natural alignment of power-of-two-sized types. Differential revision: https://reviews.llvm.org/D73245
This commit is contained in:
@@ -24,6 +24,14 @@ struct NoDefault {
|
||||
NoDefault(int) {}
|
||||
};
|
||||
|
||||
#if TEST_STD_VER < 11
|
||||
struct natural_alignment {
|
||||
long t1;
|
||||
long long t2;
|
||||
double t3;
|
||||
long double t4;
|
||||
};
|
||||
#endif
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
@@ -52,13 +60,17 @@ int main(int, char**)
|
||||
LIBCPP_ASSERT(p != nullptr);
|
||||
}
|
||||
{
|
||||
#if TEST_STD_VER < 11
|
||||
typedef natural_alignment T;
|
||||
#else
|
||||
typedef std::max_align_t T;
|
||||
#endif
|
||||
typedef std::array<T, 0> C;
|
||||
const C c = {};
|
||||
const T* p = c.data();
|
||||
LIBCPP_ASSERT(p != nullptr);
|
||||
std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p);
|
||||
assert(pint % TEST_ALIGNOF(std::max_align_t) == 0);
|
||||
assert(pint % TEST_ALIGNOF(T) == 0);
|
||||
}
|
||||
{
|
||||
typedef NoDefault T;
|
||||
|
||||
Reference in New Issue
Block a user