diff options
author | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
commit | 056abd2059c65a3e908193aeae16fad98017437c (patch) | |
tree | 2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /test/Analysis/new-with-exceptions.cpp | |
parent | cc73504950eb7b5dff2dded9bedd67bc36d64641 (diff) | |
download | FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.zip FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.tar.gz |
Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2):
http://llvm.org/svn/llvm-project/cfe/branches/release_32@168974
Diffstat (limited to 'test/Analysis/new-with-exceptions.cpp')
-rw-r--r-- | test/Analysis/new-with-exceptions.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/Analysis/new-with-exceptions.cpp b/test/Analysis/new-with-exceptions.cpp new file mode 100644 index 0000000..d909f1f --- /dev/null +++ b/test/Analysis/new-with-exceptions.cpp @@ -0,0 +1,71 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -std=c++11 -fexceptions -fcxx-exceptions -verify -DEXCEPTIONS %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -std=c++11 -verify %s + +void clang_analyzer_eval(bool); + +typedef __typeof__(sizeof(int)) size_t; +extern "C" void *malloc(size_t); + +// This is the standard placement new. +inline void* operator new(size_t, void* __p) throw() +{ + return __p; +} + +struct NoThrow { + void *operator new(size_t) throw(); +}; + +struct NoExcept { + void *operator new(size_t) noexcept; +}; + +struct DefaultThrow { + void *operator new(size_t); +}; + +struct ExplicitThrow { + void *operator new(size_t) throw(int); +}; + +void testNew() { + clang_analyzer_eval(new NoThrow); // expected-warning{{UNKNOWN}} + clang_analyzer_eval(new NoExcept); // expected-warning{{UNKNOWN}} + + clang_analyzer_eval(new DefaultThrow); + clang_analyzer_eval(new ExplicitThrow); +#ifdef EXCEPTIONS + // expected-warning@-3 {{TRUE}} + // expected-warning@-3 {{TRUE}} +#else + // expected-warning@-6 {{UNKNOWN}} + // expected-warning@-6 {{UNKNOWN}} +#endif +} + +void testNewArray() { + clang_analyzer_eval(new NoThrow[2]); + clang_analyzer_eval(new NoExcept[2]); + clang_analyzer_eval(new DefaultThrow[2]); + clang_analyzer_eval(new ExplicitThrow[2]); +#ifdef EXCEPTIONS + // expected-warning@-5 {{TRUE}} + // expected-warning@-5 {{TRUE}} + // expected-warning@-5 {{TRUE}} + // expected-warning@-5 {{TRUE}} +#else + // expected-warning@-10 {{UNKNOWN}} + // expected-warning@-10 {{UNKNOWN}} + // expected-warning@-10 {{UNKNOWN}} + // expected-warning@-10 {{UNKNOWN}} +#endif +} + +extern void *operator new[](size_t, int) noexcept; + +void testNewArrayNoThrow() { + clang_analyzer_eval(new (1) NoThrow[2]); // expected-warning{{UNKNOWN}} + clang_analyzer_eval(new (1) NoExcept[2]); // expected-warning{{UNKNOWN}} + clang_analyzer_eval(new (1) DefaultThrow[2]); // expected-warning{{UNKNOWN}} + clang_analyzer_eval(new (1) ExplicitThrow[2]); // expected-warning{{UNKNOWN}} +} |