diff options
author | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
---|---|---|
committer | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
commit | 222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch) | |
tree | 7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/Analysis/misc-ps-cxx0x.cpp | |
parent | 3d206f03985b50beacae843d880bccdc91a9f424 (diff) |
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/Analysis/misc-ps-cxx0x.cpp')
-rw-r--r-- | clang/test/Analysis/misc-ps-cxx0x.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/clang/test/Analysis/misc-ps-cxx0x.cpp b/clang/test/Analysis/misc-ps-cxx0x.cpp new file mode 100644 index 0000000..b4dee31 --- /dev/null +++ b/clang/test/Analysis/misc-ps-cxx0x.cpp @@ -0,0 +1,75 @@ +// RUN: %clang --analyze -std=c++11 %s -Xclang -verify -o /dev/null + +void test_static_assert() { + static_assert(sizeof(void *) == sizeof(void*), "test_static_assert"); +} + +void test_analyzer_working() { + int *p = 0; + *p = 0xDEADBEEF; // expected-warning {{null}} +} + +// Test that pointer-to-member functions don't cause the analyzer +// to crash. +struct RDar10243398 { + void bar(int x); +}; + +typedef void (RDar10243398::*RDar10243398MemberFn)(int x); + +void test_rdar10243398(RDar10243398 *p) { + RDar10243398MemberFn q = &RDar10243398::bar; + ((*p).*(q))(1); +} + +// Tests for CXXTemporaryObjectExpr. +struct X { + X( int *ip, int ); +}; + +// Test to see if CXXTemporaryObjectExpr is being handled. +int tempobj1() +{ + int j; + int i; + X a = X( &j, 1 ); + + return i; // expected-warning {{Undefined or garbage value returned to caller}} +} + +// Test to see if CXXTemporaryObjectExpr invalidates arguments. +int tempobj2() +{ + int j; + X a = X( &j, 1 ); + + return j; // no-warning +} + + +// Test for correct handling of C++ ForRange statement. +void test1() { + int array[2] = { 1, 2 }; + int j = 0; + for ( int i : array ) + j += i; + int *p = 0; + *p = 0xDEADBEEF; // expected-warning {{null}} +} + +void test2() { + int array[2] = { 1, 2 }; + int j = 0; + for (int i : array) + j += i; + if (j == 3) + return; + int *p = 0; + *p = 0xDEADBEEF; // no-warning +} + +// Do not crash on the following when constructing the +// callgraph. +struct RDar11178609 { + ~RDar11178609() = delete; +}; |