Clang Project

clang_source_code/test/PCH/cxx1z-aligned-alloc.cpp
1// No PCH:
2// RUN: %clang_cc1 -pedantic -fsized-deallocation -std=c++1z -include %s -verify %s
3//
4// With PCH:
5// RUN: %clang_cc1 -pedantic -fsized-deallocation -std=c++1z -emit-pch %s -o %t
6// RUN: %clang_cc1 -pedantic -fsized-deallocation -std=c++1z -include-pch %t -verify %s
7
8// expected-no-diagnostics
9
10#ifndef HEADER
11#define HEADER
12
13using size_t = decltype(sizeof(0));
14
15// Call the overaligned form of 'operator new'.
16struct alignas(256) Q { int n; };
17void *f() { return new Q; }
18
19// Extract the std::align_val_t type from the implicit declaration of operator delete.
20template<typename AlignValT>
21AlignValT extract(void (*)(void*, size_t, AlignValT));
22using T = decltype(extract(&operator delete));
23
24#else
25
26// ok, calls aligned allocation via placement syntax
27void *q = new (T{16}) Q;
28
29namespace std {
30  enum class align_val_t : size_t {};
31}
32
33using T = std::align_val_t; // ok, same type
34
35#endif
36