1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -std=c++1z -Wc++14-compat -verify %s -DCPP17
7 if (int x = f()) { // expected-note 2{{previous definition}}
8 int x; // expected-error{{redefinition of 'x'}}
10 int x; // expected-error{{redefinition of 'x'}}
15 if (int x = f()) // expected-note 2{{previous definition}}
16 int x; // expected-error{{redefinition of 'x'}}
18 int x; // expected-error{{redefinition of 'x'}}
21 void ifInitStatement() {
24 if (int I = 0; true) {}
25 if (Var + Var; true) {}
28 // expected-warning@-4 {{if initialization statements are incompatible with C++ standards before C++17}}
29 // expected-warning@-4 {{if initialization statements are incompatible with C++ standards before C++17}}
30 // expected-warning@-4 {{if initialization statements are incompatible with C++ standards before C++17}}
32 // expected-warning@-8 {{'if' initialization statements are a C++17 extension}}
33 // expected-warning@-8 {{'if' initialization statements are a C++17 extension}}
34 // expected-warning@-8 {{'if' initialization statements are a C++17 extension}}
38 void switchInitStatement() {
41 switch (int I = 0; Var) {}
42 switch (Var + Var; Var) {}
45 // expected-warning@-4 {{switch initialization statements are incompatible with C++ standards before C++17}}
46 // expected-warning@-4 {{switch initialization statements are incompatible with C++ standards before C++17}}
47 // expected-warning@-4 {{switch initialization statements are incompatible with C++ standards before C++17}}
49 // expected-warning@-8 {{'switch' initialization statements are a C++17 extension}}
50 // expected-warning@-8 {{'switch' initialization statements are a C++17 extension}}
51 // expected-warning@-8 {{'switch' initialization statements are a C++17 extension}}
55 // TODO: Better diagnostics for while init statements.
56 void whileInitStatement() {
57 while (int I = 10; I--); // expected-error {{expected ')'}}
58 // expected-note@-1 {{to match this '('}}
59 // expected-error@-2 {{use of undeclared identifier 'I'}}
62 while (Var + Var; Var--) {} // expected-error {{expected ')'}}
63 // expected-note@-1 {{to match this '('}}
64 // expected-error@-2 {{expected ';' after expression}}
65 // expected-error@-3 {{expected expression}}
66 // expected-warning@-4 {{while loop has empty body}}
67 // expected-note@-5 {{put the semicolon on a separate line to silence this warning}}
70 // TODO: This is needed because clang can't seem to diagnose invalid syntax after the
71 // last loop above. It would be nice to remove this.
72 void whileInitStatement2() {
73 while (; false) {} // expected-error {{expected expression}}
74 // expected-warning@-1 {{expression result unused}}
75 // expected-error@-2 {{expected ';' after expression}}
76 // expected-error@-3 {{expected expression}}