aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2013-05-06 16:48:20 +0000
committerJordan Rose <jordan_rose@apple.com>2013-05-06 16:48:20 +0000
commit6376703eb3325fe41233aed234fde81164af42a1 (patch)
tree0f214678f63f7f3eb4dcfd44bc68d024a7def91f /test
parent2624b8157660902303bfce5551cfdd38272d01e5 (diff)
[analyzer] Handle CXXTemporaryObjectExprs in compound literals.
This occurs because in C++11 the compound literal syntax can trigger a constructor call via list-initialization. That is, "Point{x, y}" and "(Point){x, y}" end up being equivalent. If this occurs, the inner CXXConstructExpr will have already handled the object construction; the CompoundLiteralExpr just needs to propagate that value forwards. <rdar://problem/13804098> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181213 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Analysis/temporaries.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/test/Analysis/temporaries.cpp b/test/Analysis/temporaries.cpp
index 32a4d3bef4..efc0825470 100644
--- a/test/Analysis/temporaries.cpp
+++ b/test/Analysis/temporaries.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify -w %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify -w -std=c++03 %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify -w -std=c++11 %s
extern bool clang_analyzer_eval(bool);
@@ -76,3 +77,35 @@ namespace rdar13281951 {
}
}
+namespace compound_literals {
+ struct POD {
+ int x, y;
+ };
+ struct HasCtor {
+ HasCtor(int x, int y) : x(x), y(y) {}
+ int x, y;
+ };
+ struct HasDtor {
+ int x, y;
+ ~HasDtor();
+ };
+ struct HasCtorDtor {
+ HasCtorDtor(int x, int y) : x(x), y(y) {}
+ ~HasCtorDtor();
+ int x, y;
+ };
+
+ void test() {
+ clang_analyzer_eval(((POD){1, 42}).y == 42); // expected-warning{{TRUE}}
+ clang_analyzer_eval(((HasDtor){1, 42}).y == 42); // expected-warning{{TRUE}}
+
+#if __cplusplus >= 201103L
+ clang_analyzer_eval(((HasCtor){1, 42}).y == 42); // expected-warning{{TRUE}}
+
+ // FIXME: should be TRUE, but we don't inline the constructors of
+ // temporaries because we can't model their destructors yet.
+ clang_analyzer_eval(((HasCtorDtor){1, 42}).y == 42); // expected-warning{{UNKNOWN}}
+#endif
+ }
+}
+