summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/condition.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-09-10 02:17:11 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-09-10 02:17:11 +0000
commit7620ee45503df50f9843fca2ed7918ae7f6a88d6 (patch)
treecfa5bebdbf658ee561a37563b8ab6cfe67d1a98f /clang/test/SemaCXX/condition.cpp
parent791dc3cd4edac2906e7b2f8eaa727dddaac7670a (diff)
downloadbcm5719-llvm-7620ee45503df50f9843fca2ed7918ae7f6a88d6.tar.gz
bcm5719-llvm-7620ee45503df50f9843fca2ed7918ae7f6a88d6.zip
Implement Sema support for the 'condition' part of C++ selection-statements and iteration-statements (if/switch/while/for).
llvm-svn: 56044
Diffstat (limited to 'clang/test/SemaCXX/condition.cpp')
-rw-r--r--clang/test/SemaCXX/condition.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/condition.cpp b/clang/test/SemaCXX/condition.cpp
new file mode 100644
index 00000000000..e535a00f41d
--- /dev/null
+++ b/clang/test/SemaCXX/condition.cpp
@@ -0,0 +1,33 @@
+// RUN: clang -fsyntax-only -verify %s
+
+void test() {
+ int a;
+ if (a) ++a;
+ if (int x=0) ++x;
+
+ typedef int arr[10];
+ while (arr x=0) ; // expected-error: {{an array type is not allowed here}} expected-error: {{initialization with "{...}" expected for array}}
+ while (int f()=0) ; // expected-error: {{a function type is not allowed here}}
+
+ struct S {} s;
+ if (s) ++a; // expected-error: {{expression must have bool type (or be convertible to bool) ('struct S' invalid)}}
+ while (struct S x=s) ; // expected-error: {{expression must have bool type (or be convertible to bool) ('struct S' invalid)}}
+ switch (s) {} // expected-error: {{statement requires expression of integer type ('struct S' invalid)}}
+
+ while (struct S {} x=0) ; // expected-error: {{types may not be defined in conditions}} expected-error: {{incompatible type}} expected-error: {{expression must have bool type}}
+ while (struct {} x=0) ; // expected-error: {{types may not be defined in conditions}} expected-error: {{incompatible type}} expected-error: {{expression must have bool type}}
+ switch (enum {E} x=0) ; // expected-error: {{types may not be defined in conditions}}
+
+ if (int x=0) { // expected-error: {{previous definition is here}}
+ int x; // expected-error: {{redefinition of 'x'}}
+ }
+ else
+ int x; // expected-error: {{redefinition of 'x'}}
+ while (int x=0) int x; // expected-error: {{redefinition of 'x'}} expected-error: {{previous definition is here}}
+ while (int x=0) { int x; } // expected-error: {{redefinition of 'x'}} expected-error: {{previous definition is here}}
+ for (int x; int x=0; ) ; // expected-error: {{redefinition of 'x'}} expected-error: {{previous definition is here}}
+ for (int x; ; ) int x; // expected-error: {{redefinition of 'x'}} expected-error: {{previous definition is here}}
+ for (; int x=0; ) int x; // expected-error: {{redefinition of 'x'}} expected-error: {{previous definition is here}}
+ for (; int x=0; ) { int x; } // expected-error: {{redefinition of 'x'}} expected-error: {{previous definition is here}}
+ switch (int x=0) { default: int x; } // expected-error: {{redefinition of 'x'}} expected-error: {{previous definition is here}}
+}
OpenPOWER on IntegriCloud