1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -std=c++11 -fexceptions -fcxx-exceptions -verify %s 2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -std=c++11 -verify %s 3*f4a2713aSLionel Sambuc 4*f4a2713aSLionel Sambuc void clang_analyzer_eval(bool); 5*f4a2713aSLionel Sambuc 6*f4a2713aSLionel Sambuc typedef __typeof__(sizeof(int)) size_t; 7*f4a2713aSLionel Sambuc extern "C" void *malloc(size_t); 8*f4a2713aSLionel Sambuc 9*f4a2713aSLionel Sambuc // This is the standard placement new. operator new(size_t,void * __p)10*f4a2713aSLionel Sambucinline void* operator new(size_t, void* __p) throw() 11*f4a2713aSLionel Sambuc { 12*f4a2713aSLionel Sambuc return __p; 13*f4a2713aSLionel Sambuc } 14*f4a2713aSLionel Sambuc 15*f4a2713aSLionel Sambuc struct NoThrow { 16*f4a2713aSLionel Sambuc void *operator new(size_t) throw(); 17*f4a2713aSLionel Sambuc }; 18*f4a2713aSLionel Sambuc 19*f4a2713aSLionel Sambuc struct NoExcept { 20*f4a2713aSLionel Sambuc void *operator new(size_t) noexcept; 21*f4a2713aSLionel Sambuc }; 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc struct DefaultThrow { 24*f4a2713aSLionel Sambuc void *operator new(size_t); 25*f4a2713aSLionel Sambuc }; 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambuc struct ExplicitThrow { 28*f4a2713aSLionel Sambuc void *operator new(size_t) throw(int); 29*f4a2713aSLionel Sambuc }; 30*f4a2713aSLionel Sambuc testNew()31*f4a2713aSLionel Sambucvoid testNew() { 32*f4a2713aSLionel Sambuc clang_analyzer_eval(new NoThrow); // expected-warning{{UNKNOWN}} 33*f4a2713aSLionel Sambuc clang_analyzer_eval(new NoExcept); // expected-warning{{UNKNOWN}} 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel Sambuc clang_analyzer_eval(new DefaultThrow); // expected-warning{{TRUE}} 36*f4a2713aSLionel Sambuc clang_analyzer_eval(new ExplicitThrow); // expected-warning{{TRUE}} 37*f4a2713aSLionel Sambuc } 38*f4a2713aSLionel Sambuc testNewArray()39*f4a2713aSLionel Sambucvoid testNewArray() { 40*f4a2713aSLionel Sambuc clang_analyzer_eval(new NoThrow[2]); // expected-warning{{TRUE}} 41*f4a2713aSLionel Sambuc clang_analyzer_eval(new NoExcept[2]); // expected-warning{{TRUE}} 42*f4a2713aSLionel Sambuc clang_analyzer_eval(new DefaultThrow[2]); // expected-warning{{TRUE}} 43*f4a2713aSLionel Sambuc clang_analyzer_eval(new ExplicitThrow[2]); // expected-warning{{TRUE}} 44*f4a2713aSLionel Sambuc } 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambuc extern void *operator new[](size_t, int) noexcept; 47*f4a2713aSLionel Sambuc testNewArrayNoThrow()48*f4a2713aSLionel Sambucvoid testNewArrayNoThrow() { 49*f4a2713aSLionel Sambuc clang_analyzer_eval(new (1) NoThrow[2]); // expected-warning{{UNKNOWN}} 50*f4a2713aSLionel Sambuc clang_analyzer_eval(new (1) NoExcept[2]); // expected-warning{{UNKNOWN}} 51*f4a2713aSLionel Sambuc clang_analyzer_eval(new (1) DefaultThrow[2]); // expected-warning{{UNKNOWN}} 52*f4a2713aSLionel Sambuc clang_analyzer_eval(new (1) ExplicitThrow[2]); // expected-warning{{UNKNOWN}} 53*f4a2713aSLionel Sambuc } 54