[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / operator-new-size-diagnose_if.cpp
blob62ac2ac3a03837e6a68b72294a5c6ed822049b17
1 // RUN: %clang_cc1 %s -verify -fno-builtin -std=c++14
3 using size_t = decltype(sizeof(int));
5 #define _diagnose_if(...) __attribute__((diagnose_if(__VA_ARGS__)))
7 namespace operator_new {
8 struct T0 {
9 int j = 0;
10 static void *operator new(size_t i) _diagnose_if(i == sizeof(int), "yay", "warning"); // expected-note{{from 'diagnose_if'}}
13 struct T1 {
14 int j = 0;
15 static void *operator new[](size_t i) _diagnose_if(i == 8 * sizeof(int), "yay", "warning"); // expected-note 2{{from 'diagnose_if'}}
18 void run(int x) {
19 new T0; // expected-warning{{yay}}
20 new T1[8]; // expected-warning{{yay}}
21 new T1[4][2]; // expected-warning{{yay}}
22 new T1[x]; // no warning.
24 } // namespace operator_new