Skip to content

Commit

Permalink
Diagnose missing parameter after a this-specifier or parameter-direct…
Browse files Browse the repository at this point in the history
…ion, closes hsutter#397 and hsutter#505
  • Loading branch information
hsutter authored and zaucy committed Dec 5, 2023
1 parent a81897e commit 4e2f7ad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion regression-tests/test-results/version
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

cppfront compiler v0.2.1 Build 8730:1258
cppfront compiler v0.2.1 Build 8809:1505
Copyright(c) Herb Sutter All rights reserved

SPDX-License-Identifier: CC-BY-NC-ND-4.0
Expand Down
2 changes: 1 addition & 1 deletion source/build.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"8809:1416"
"8809:1505"
16 changes: 16 additions & 0 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -5777,25 +5777,32 @@ class parser
)
-> std::unique_ptr<parameter_declaration_node>
{
auto modifier = std::string();
auto modifier_plural = "";

auto n = std::make_unique<parameter_declaration_node>();
n->pass = is_returns ? passing_style::out : passing_style::in;
n->pos = curr().position();

// Handle optional this-specifier
//
if (curr() == "implicit") {
modifier = curr().as_string_view();
n->mod = parameter_declaration_node::modifier::implicit;
next();
}
else if (curr() == "virtual") {
modifier = curr().as_string_view();
n->mod = parameter_declaration_node::modifier::virtual_;
next();
}
else if (curr() == "override") {
modifier = curr().as_string_view();
n->mod = parameter_declaration_node::modifier::override_;
next();
}
else if (curr() == "final") {
modifier = curr().as_string_view();
n->mod = parameter_declaration_node::modifier::final_;
next();
}
Expand All @@ -5806,6 +5813,12 @@ class parser
dir != passing_style::invalid
)
{
if (!modifier.empty()) {
modifier += " ";
modifier_plural = "s";
}
modifier += curr().as_string_view();

if (is_returns)
{
if (dir == passing_style::in) {
Expand Down Expand Up @@ -5840,6 +5853,9 @@ class parser
// Now the main declaration
//
if (!(n->declaration = declaration(false, true, is_template))) {
if (!modifier.empty()) {
error( "'" + modifier + "' modifier" + modifier_plural + " must be followed by a valid parameter declaration", false);
}
return {};
}

Expand Down

0 comments on commit 4e2f7ad

Please sign in to comment.