Skip to content

Commit 089b785

Browse files
authored
Provide hint for auto declaration in Cpp2 code (#342)
* Provide hint for `auto` declaration in Cpp2 code Like the hints for `namespace`/`class` keywords. * Try to parse name for auto declaration Use it in error message.
1 parent dced321 commit 089b785

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

source/parse.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5597,6 +5597,21 @@ class parser
55975597

55985598
// Provide some useful Cpp1->Cpp2 migration diagnostics for common mistakes
55995599
//
5600+
if (
5601+
id->get_token()
5602+
&& *id->get_token() == "auto"
5603+
)
5604+
{
5605+
auto name = std::string{"v"};
5606+
if (peek(0) && peek(0)->type() == lexeme::Identifier) {
5607+
name = peek(0)->to_string(true);
5608+
}
5609+
errors.emplace_back(
5610+
curr().position(),
5611+
"to define a variable " + name + " of type T, write '" + name + ": T = /* initializer */'"
5612+
);
5613+
return {};
5614+
}
56005615
if (
56015616
id->get_token()
56025617
&& *id->get_token() == "namespace"

0 commit comments

Comments
 (0)