Skip to content

Commit 0a46d09

Browse files
committed
Add helpful diagnostics when rejecting possible attempts to use C-style [ ] arrays (not Cpp2), closes hsutter#197
1 parent 690cdf3 commit 0a46d09

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

source/parse.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,8 +1687,9 @@ class parser
16871687
if (term.op->type() == lexeme::LeftBracket)
16881688
{
16891689
term.expr_list = expression_list(term.op);
1690-
if (!term.expr_list) {
1691-
error("subscript expression [ ] must not be empty");
1690+
if (!term.expr_list || term.expr_list->expressions.empty()) {
1691+
error("subscript expression [ ] must not be empty (if you were trying to name a C-style array type, use 'std::array' instead)");
1692+
next();
16921693
return {};
16931694
}
16941695
if (curr().type() != lexeme::RightBracket) {
@@ -2121,26 +2122,30 @@ class parser
21212122
n->pos = id->position();
21222123
n->id = std::move(id);
21232124
assert (n->id.index() == type_id_node::qualified);
2124-
return n;
21252125
}
2126-
if (auto id = unqualified_id()) {
2126+
else if (auto id = unqualified_id()) {
21272127
n->pos = id->position();
21282128
n->id = std::move(id);
21292129
assert (n->id.index() == type_id_node::unqualified);
2130-
return n;
21312130
}
2132-
if (curr().type() == lexeme::Keyword || curr().type() == lexeme::Cpp2FixedType) {
2131+
else if (curr().type() == lexeme::Keyword || curr().type() == lexeme::Cpp2FixedType) {
21332132
n->pos = curr().position();
21342133
n->id = &curr();
21352134
next();
21362135
assert (n->id.index() == type_id_node::keyword);
2137-
return n;
21382136
}
2139-
2140-
if (!n->pc_qualifiers.empty()) {
2137+
else {
2138+
if (!n->pc_qualifiers.empty()) {
21412139
error("'*'/'const' type qualifiers must be followed by a type name or '_' wildcard");
2140+
}
2141+
return {};
21422142
}
2143-
return {};
2143+
2144+
if (curr().type() == lexeme::LeftBracket) {
2145+
error("C-style array types are not allowed, use std::array instead");
2146+
return {};
2147+
}
2148+
return n;
21442149
}
21452150

21462151

0 commit comments

Comments
 (0)