64 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++982// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++113 4typedef __SIZE_TYPE__ size_t;5 6#if __cplusplus >= 201103L7struct S1 {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'}}10 }11 void *operator new[](size_t n) noexcept {12 return __null;13 }14};15#endif16 17struct S2 {18 static size_t x;19 void *operator new(size_t n) throw() {20 return 0;21 }22 void *operator new[](size_t n) {23 return (void*)0;24#if __cplusplus >= 201103L25 // expected-warning@-2 {{'operator new[]' should not return a null pointer unless it is declared 'throw()' or 'noexcept'}}26#else27 // expected-warning-re@-4 {{'operator new[]' should not return a null pointer unless it is declared 'throw()'{{$}}}}28#endif29 }30};31 32struct S3 {33 void *operator new(size_t n) {34 return 1-1;35#if __cplusplus >= 201103L36 // expected-error@-2 {{cannot initialize return object of type 'void *' with an rvalue of type 'int'}}37#else38 // 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()'}}40#endif41 }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()'}}44 }45};46 47#if __cplusplus >= 201103L48template<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}}51 }52};53template struct S4<true>;54template struct S4<false>; // expected-note {{in instantiation of}}55#endif56 57template<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}}60 }61};62template struct S5<>;63template struct S5<int>; // expected-note {{in instantiation of}}64