[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / warn-new-overaligned.cpp
blob52e58c283f5b900ec9e2c0633b3585b1274ab6f3
1 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -Wover-aligned -verify=precxx17 %std_cxx98-14 %s
2 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -Wover-aligned -verify=cxx17 %std_cxx17- %s
4 namespace test1 {
5 struct Test {
6 template <typename T>
7 struct SeparateCacheLines {
8 T data;
9 } __attribute__((aligned(256)));
11 SeparateCacheLines<int> high_contention_data[10];
14 void helper() {
15 Test t;
16 new Test; // precxx17-warning {{type 'Test' requires 256 bytes of alignment and the default allocator only guarantees}}
17 new Test[10]; // precxx17-warning {{type 'Test' requires 256 bytes of alignment and the default allocator only guarantees}}
21 namespace test2 {
22 struct S {
23 char c[256];
26 class Test {
27 typedef S __attribute__((aligned(256))) alignedS;
28 alignedS high_contention_data[10];
31 void helper() {
32 Test t;
33 new Test; // precxx17-warning {{type 'Test' requires 256 bytes of alignment and the default allocator only guarantees}}
34 new Test[10]; // precxx17-warning {{type 'Test' requires 256 bytes of alignment and the default allocator only guarantees}}
38 namespace test3 {
39 struct Test {
40 template <typename T>
41 struct SeparateCacheLines {
42 T data;
43 } __attribute__((aligned(256)));
45 void* operator new(unsigned long) {
46 return 0; // precxx17-warning {{'operator new' should not return a null pointer unless it is declared 'throw()'}} \
47 cxx17-warning {{'operator new' should not return a null pointer unless it is declared 'throw()' or 'noexcept'}}
50 SeparateCacheLines<int> high_contention_data[10];
53 void helper() {
54 Test t;
55 new Test;
56 new Test[10]; // precxx17-warning {{type 'Test' requires 256 bytes of alignment and the default allocator only guarantees}}
60 namespace test4 {
61 struct Test {
62 template <typename T>
63 struct SeparateCacheLines {
64 T data;
65 } __attribute__((aligned(256)));
67 void* operator new[](unsigned long) {
68 return 0; // precxx17-warning {{'operator new[]' should not return a null pointer unless it is declared 'throw()'}} \
69 cxx17-warning {{'operator new[]' should not return a null pointer unless it is declared 'throw()' or 'noexcept'}}
72 SeparateCacheLines<int> high_contention_data[10];
75 void helper() {
76 Test t;
77 new Test; // precxx17-warning {{type 'Test' requires 256 bytes of alignment and the default allocator only guarantees}}
78 new Test[10];