fortran/openmp.cc: Fix var init and locus use to avoid uninit values [PR fortran...
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1y / sized-dealloc1.C
blob846fce6199030d3b16c10091c3392e59c11814a6
1 // Test for C++14 sized deallocation.  The operators delete defined below
2 // should be called only in C++14 mode and above.
3 // { dg-do run }
5 extern "C" void abort();
6 typedef __SIZE_TYPE__ size_t;
7 #include <new>
9 bool called;
10 void operator delete[] (void *p, size_t s) throw()
12   called = true;
13   operator delete[] (p);
16 void operator delete (void *p, size_t s) throw()
18   called = true;
19   operator delete (p);
22 void operator delete[] (void *p, size_t s, const std::nothrow_t &) throw()
24   called = true;
25   operator delete[] (p);
28 void operator delete (void *p, size_t s, const std::nothrow_t &) throw()
30   called = true;
31   operator delete (p);
34 struct A { ~A(){} };
36 struct B { };
38 struct C;
40 struct D { ~D(){}; D() { throw 1; } };
42 int main()
44   /* * If the type is complete and if, for the second alternative (delete
45      array) only, the operand is a pointer to a class type with a
46      non-trivial destructor or a (possibly multi-dimensional) array
47      thereof, the function with two parameters is selected.
49      * Otherwise, it is unspecified which of the two deallocation functions
50      is selected. */
51   delete new int;
52   if (called != (__cplusplus >= 201402L)) abort(); called = false;
54   delete new A;
55   if (called != (__cplusplus >= 201402L)) abort(); called = false;
57   delete[] new A[2];
58   if (called != (__cplusplus >= 201402L)) abort(); called = false;
60   delete new B;
61   if (called != (__cplusplus >= 201402L)) abort(); called = false;
63   /* N3778 added the sized placement deallocation functions, but the core
64      language rules don't provide any way they would be called.  */
65   try { new (std::nothrow) D; } catch (int) {}
66   if (called) abort();
68   try { new (std::nothrow) D[2]; } catch (int) {}
69   if (called) abort();
71   /* Make sure we don't try to use the size of an array that doesn't have a
72      cookie.  */
73   delete[] new B[2];
74   if (called) abort();