///
Parser::TPResult Parser::TryParseBracketDeclarator() {
ConsumeBracket();
- if (!SkipUntil(tok::r_square, StopAtSemi))
+
+ // A constant-expression cannot begin with a '{', but the
+ // expr-or-braced-init-list of a postfix-expression can.
+ if (Tok.is(tok::l_brace))
+ return TPResult::False;
+
+ if (!SkipUntil(tok::r_square, tok::comma, StopAtSemi | StopBeforeMatch))
return TPResult::Error;
+ // If we hit a comma before the ']', this is not a constant-expression,
+ // but might still be the expr-or-braced-init-list of a postfix-expression.
+ if (Tok.isNot(tok::r_square))
+ return TPResult::False;
+
+ ConsumeBracket();
return TPResult::Ambiguous;
}
auto (*r)() -> int(*)(unknown + 1); // expected-error {{undeclared identifier 'unknown'}}
int f(unknown const x); // expected-error {{unknown type name 'unknown'}}
+
+// Disambiguating an array declarator from an array subscripting.
+void arr() {
+ int x[] = {1}; // expected-note 2{{previous}}
+
+ // This is array indexing not an array declarator because a comma expression
+ // is not syntactically a constant-expression.
+ int(x[1,1]); // expected-warning 2{{unused}}
+
+ // This is array indexing not an array declaration because a braced-init-list
+ // is not syntactically a constant-expression.
+ int(x[{0}]); // expected-error {{array subscript is not an integer}}
+ struct A {
+ struct Q { int n; };
+ int operator[](Q);
+ } a;
+ int(a[{0}]); // expected-warning {{unused}}
+
+ // These are array declarations.
+ int(x[(1,1)]); // expected-error {{redefinition}}
+ int(x[true ? 1,1 : 1]); // expected-error {{redefinition}}
+}