summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/warn-for-var-in-else.cpp
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-06-02 17:58:47 +0000
committered <ed@FreeBSD.org>2009-06-02 17:58:47 +0000
commitf27e5a09a0d815b8a4814152954ff87dadfdefc0 (patch)
treece7d964cbb5e39695b71481698f10cb099c23d4a /test/SemaCXX/warn-for-var-in-else.cpp
downloadFreeBSD-src-f27e5a09a0d815b8a4814152954ff87dadfdefc0.zip
FreeBSD-src-f27e5a09a0d815b8a4814152954ff87dadfdefc0.tar.gz
Import Clang, at r72732.
Diffstat (limited to 'test/SemaCXX/warn-for-var-in-else.cpp')
-rw-r--r--test/SemaCXX/warn-for-var-in-else.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-for-var-in-else.cpp b/test/SemaCXX/warn-for-var-in-else.cpp
new file mode 100644
index 0000000..3368da2
--- /dev/null
+++ b/test/SemaCXX/warn-for-var-in-else.cpp
@@ -0,0 +1,30 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+// rdar://6425550
+int bar();
+void do_something(int);
+
+int foo() {
+ if (int X = bar()) {
+ return X;
+ } else {
+ do_something(X); // expected-warning{{'X' is always zero in this context}}
+ }
+}
+
+bool foo2() {
+ if (bool B = bar()) {
+ if (int Y = bar()) {
+ return B;
+ } else {
+ do_something(Y); // expected-warning{{'Y' is always zero in this context}}
+ return B;
+ }
+ } else {
+ if (bool B2 = B) { // expected-warning{{'B' is always false in this context}}
+ do_something(B); // expected-warning{{'B' is always false in this context}}
+ } else if (B2) { // expected-warning{{'B2' is always false in this context}}
+ do_something(B); // expected-warning{{'B' is always false in this context}}
+ }
+ return B; // expected-warning{{'B' is always false in this context}}
+ }
+}
OpenPOWER on IntegriCloud