summaryrefslogtreecommitdiffstats
path: root/clang/test/Parser
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-06-29 21:17:59 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-06-29 21:17:59 +0000
commitc7a05a9f4d589f562c4fd043fb8e605e536b0dec (patch)
tree582b215d2a5518247b9a0fe1125579511d89f645 /clang/test/Parser
parent03c38af1097a4da22f39cec4cb16d0fcbd935dd6 (diff)
downloadbcm5719-llvm-c7a05a9f4d589f562c4fd043fb8e605e536b0dec.tar.gz
bcm5719-llvm-c7a05a9f4d589f562c4fd043fb8e605e536b0dec.zip
P0305R1: Parsing support for init-statements in 'if' and 'switch' statements.
No semantic analysis yet. This is a pain to disambiguate correctly, because the parsing rules for the declaration form of a condition and of an init-statement are quite different -- for a token sequence that looks like a declaration, we frequently need to disambiguate all the way to the ')' or ';'. We could do better here in some cases by stopping disambiguation once we've decided whether we've got an expression or not (rather than keeping going until we know whether it's an init-statement declaration or a condition declaration), by unifying our parsing code for the two types of declaration and moving the syntactic checks into Sema; if this has a measurable impact on parsing performance, I'll look into that. llvm-svn: 274169
Diffstat (limited to 'clang/test/Parser')
-rw-r--r--clang/test/Parser/cxx1z-init-statement.cpp47
-rw-r--r--clang/test/Parser/extra-semi.cpp1
2 files changed, 47 insertions, 1 deletions
diff --git a/clang/test/Parser/cxx1z-init-statement.cpp b/clang/test/Parser/cxx1z-init-statement.cpp
new file mode 100644
index 00000000000..e8621babaa8
--- /dev/null
+++ b/clang/test/Parser/cxx1z-init-statement.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -std=c++1z -verify %s -Wno-vexing-parse
+
+int g, h;
+typedef int T;
+int f() {
+ // init-statement declarations
+ if (T n = 0; n != 0) {} // expected-error {{not yet supported}}
+ if (T f(); f()) {} // expected-error {{not yet supported}}
+ if (T(f()); f()) {} // expected-error {{not yet supported}}
+ if (T(f()), g, h; f()) {} // expected-error {{not yet supported}}
+ if (T f(); f()) {} // expected-error {{not yet supported}}
+ if (T f(), g, h; f()) {} // expected-error {{not yet supported}}
+
+ // init-statement expressions
+ if (T{f()}; f()) {} // expected-error {{not yet supported}}
+ if (T{f()}, g, h; f()) {} // expected-error {{not yet supported}} expected-warning 2{{unused}}
+ if (T(f()), g, h + 1; f()) {} // expected-error {{not yet supported}} expected-warning 2{{unused}}
+
+ // condition declarations
+ if (T(n){g}) {}
+ if (T f()) {} // expected-error {{function type}}
+ if (T f(), g, h) {} // expected-error {{function type}}
+
+ // condition expressions
+ if (T(f())) {}
+ if (T{f()}) {}
+ if (T(f()), g, h) {} // expected-warning 2{{unused}}
+ if (T{f()}, g, h) {} // expected-warning 2{{unused}}
+
+ // none of the above
+ // FIXME: This causes a typo-correction crash, as does "void f() { +T(n)(g); }"
+ //if (T(n)(g)) {} // expected-err-FIXME {{not a function}}
+
+ // Likewise for 'switch'
+ switch (int n; n) {} // expected-error {{not yet supported}}
+ switch (g; int g = 5) {} // expected-error {{not yet supported}}
+
+ if (int a, b; int c = a) { // expected-error {{not yet supported}} expected-note 6{{previous}}
+ int a; // expected-error {{redefinition}}
+ int b; // expected-error {{redefinition}}
+ int c; // expected-error {{redefinition}}
+ } else {
+ int a; // expected-error {{redefinition}}
+ int b; // expected-error {{redefinition}}
+ int c; // expected-error {{redefinition}}
+ }
+}
diff --git a/clang/test/Parser/extra-semi.cpp b/clang/test/Parser/extra-semi.cpp
index 1a44dae411e..7287f856d8c 100644
--- a/clang/test/Parser/extra-semi.cpp
+++ b/clang/test/Parser/extra-semi.cpp
@@ -5,7 +5,6 @@
void test1(int a;) { // expected-error{{unexpected ';' before ')'}}
while (a > 5;) {} // expected-error{{unexpected ';' before ')'}}
- if (int b = 10;) {} // expected-error{{unexpected ';' before ')'}}
for (int c = 0; c < 21; ++c;) {} // expected-error{{unexpected ';' before ')'}}
int d = int(3 + 4;); // expected-error{{unexpected ';' before ')'}}
int e[5;]; // expected-error{{unexpected ';' before ']'}}
OpenPOWER on IntegriCloud