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