1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
4 typedef __SIZE_TYPE__
size_t;
6 #if __cplusplus >= 201103L
8 void *operator new(size_t n
) {
9 return nullptr; // expected-warning {{'operator new' should not return a null pointer unless it is declared 'throw()' or 'noexcept'}}
11 void *operator new[](size_t n
) noexcept
{
19 void *operator new(size_t n
) throw() {
22 void *operator new[](size_t n
) {
24 #if __cplusplus >= 201103L
25 // expected-warning@-2 {{'operator new[]' should not return a null pointer unless it is declared 'throw()' or 'noexcept'}}
27 // expected-warning-re@-4 {{'operator new[]' should not return a null pointer unless it is declared 'throw()'{{$}}}}
33 void *operator new(size_t n
) {
35 #if __cplusplus >= 201103L
36 // expected-error@-2 {{cannot initialize return object of type 'void *' with an rvalue of type 'int'}}
38 // expected-warning@-4 {{expression which evaluates to zero treated as a null pointer constant of type 'void *'}}
39 // expected-warning@-5 {{'operator new' should not return a null pointer unless it is declared 'throw()'}}
42 void *operator new[](size_t n
) {
43 return (void*)(1-1); // expected-warning {{'operator new[]' should not return a null pointer unless it is declared 'throw()'}}
47 #if __cplusplus >= 201103L
48 template<bool B
> struct S4
{
49 void *operator new(size_t n
) noexcept(B
) {
50 return 0; // expected-warning {{'operator new' should not return a null pointer}}
53 template struct S4
<true>;
54 template struct S4
<false>; // expected-note {{in instantiation of}}
57 template<typename
...T
> struct S5
{ // expected-warning 0-1{{extension}}
58 void *operator new(size_t n
) throw(T
...) {
59 return 0; // expected-warning {{'operator new' should not return a null pointer}}
63 template struct S5
<int>; // expected-note {{in instantiation of}}