llvm-project
51 строка · 1.8 Кб
1// RUN: %clang_cc1 -std=c++1z -verify %s -Wno-vexing-parse
2
3int g, h;4typedef int T;5int f() {6// init-statement declarations7if (T n = 0; n != 0) {}8if (T f(); f()) {}9if (T(f()); f()) {}10if (T(f()), g, h; f()) {}11if (T f(); f()) {}12if (T f(), g, h; f()) {}13if (T(n) = 0; n) {}14
15// init-statement expressions16if (T{f()}; f()) {} // expected-warning {{expression result unused}}17if (T{f()}, g, h; f()) {} // expected-warning 2{{left operand of comma operator has no effect}} expected-warning {{expression result unused}}18if (T(f()), g, h + 1; f()) {} // expected-warning 2{{left operand of comma operator has no effect}} expected-warning {{expression result unused}}19
20// condition declarations21if (T(n){g}) {}22if (T f()) {} // expected-error {{function type}}23if (T f(), g, h) {} // expected-error {{function type}}24if (T(n) = 0) {}25
26// condition expressions27if (T(f())) {}28if (T{f()}) {}29if (T(f()), g, h) {} // expected-warning 2{{left operand of comma operator has no effect}}30if (T{f()}, g, h) {} // expected-warning 2{{left operand of comma operator has no effect}}31
32// none of the above, disambiguated as expression (can't be a declaration)33if (T(n)(g)) {} // expected-error {{undeclared identifier 'n'}}34if (T(n)(int())) {} // expected-error {{undeclared identifier 'n'}}35
36// Likewise for 'switch'37switch (int n; n) {}38switch (g; int g = 5) {} // expected-warning {{expression result unused}}39
40if (int a, b; int c = a) { // expected-note 6{{previous}}41int a; // expected-error {{redefinition}}42int b; // expected-error {{redefinition}}43int c; // expected-error {{redefinition}}44} else {45int a; // expected-error {{redefinition}}46int b; // expected-error {{redefinition}}47int c; // expected-error {{redefinition}}48}49
50return 0;51}
52