1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s 2 // RUN: %clang_cc1 -std=c++11 -faligned-allocation -fsyntax-only -verify %s 3 // RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s 4 // RUN: %clang_cc1 -std=c++14 -faligned-allocation -fsyntax-only -verify %s 5 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s 6 // RUN: %clang_cc1 -std=c++17 -faligned-allocation -fsyntax-only -verify %s 7 8 namespace std { 9 typedef __SIZE_TYPE__ size_t; 10 struct nothrow_t {}; 11 #if __cplusplus >= 201103L 12 enum class align_val_t : size_t {}; 13 #else 14 enum align_val_t { 15 // We can't force an underlying type when targeting windows. 16 #ifndef _WIN32 17 __zero = 0, 18 __max = (size_t)-1 19 #endif 20 }; 21 #endif 22 } // namespace std 23 24 void *operator new(std::size_t count, std::align_val_t al) __attribute__((alloc_align(2))); 25 26 #define OVERALIGNED alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2) 27 28 struct OVERALIGNED A { 29 A(); 30 int n[128]; 31 }; 32 33 void *ptr_variable(int align) { return new (std::align_val_t(align)) A; } 34 void *ptr_align16() { return new (std::align_val_t(16)) A; } 35 void *ptr_align15() { return new (std::align_val_t(15)) A; } // expected-warning {{requested alignment is not a power of 2}} 36 37 struct alignas(128) S { 38 S() {} 39 }; 40 41 void *alloc_overaligned_struct() { 42 return new S; 43 } 44 45 void *alloc_overaligned_struct_with_extra_variable_alignment(int align) { 46 return new (std::align_val_t(align)) S; 47 } 48 void *alloc_overaligned_struct_with_extra_256_alignment(int align) { 49 return new (std::align_val_t(256)) S; 50 } 51 void *alloc_overaligned_struct_with_extra_255_alignment(int align) { 52 return new (std::align_val_t(255)) S; // expected-warning {{requested alignment is not a power of 2}} 53 } 54 55 std::align_val_t align_variable(int align) { return std::align_val_t(align); } 56 std::align_val_t align_align16() { return std::align_val_t(16); } 57 std::align_val_t align_align15() { return std::align_val_t(15); } 58