Skip to content

Commit 71b9cb0

Browse files
committed
Diagnose std::move only for single argument version
Closes #1167
1 parent 797569a commit 71b9cb0

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.7.1 Build 9716:1345
2+
cppfront compiler v0.7.1 Build 9717:1027
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"9716:1345"
1+
"9717:1027"

source/parse.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,17 @@ struct postfix_expression_node
930930
return ops.empty() && expr->is_id_expression();
931931
}
932932

933+
auto starts_with_function_call_with_n_parameters(int n) const
934+
-> bool
935+
{
936+
return
937+
std::ssize(ops) >= 1
938+
&& ops.front().op->type() == lexeme::LeftParen
939+
&& ops.front().expr_list
940+
&& std::ssize(ops.front().expr_list->expressions) == n
941+
;
942+
}
943+
933944
auto is_unqualified_id() const
934945
-> bool
935946
{
@@ -6874,11 +6885,14 @@ class parser
68746885
// Reject "std" :: "move" / "forward"
68756886
assert (term.id->identifier);
68766887
auto first_uid_was_std = (*term.id->identifier == "std");
6877-
auto first_time_through_loop = true;
68786888

68796889
n->ids.push_back( std::move(term) );
68806890

6881-
while (curr().type() == lexeme::Scope)
6891+
for (
6892+
auto first_time_through_loop = true;
6893+
curr().type() == lexeme::Scope;
6894+
first_time_through_loop = false
6895+
)
68826896
{
68836897
auto term = qualified_id_node::term{ &curr() };
68846898
next();
@@ -6892,17 +6906,11 @@ class parser
68926906
first_time_through_loop
68936907
&& first_uid_was_std
68946908
&& term.scope_op->type() == lexeme::Scope
6895-
)
6909+
&& *term.id->identifier == "forward"
6910+
)
68966911
{
6897-
if (*term.id->identifier == "move") {
6898-
error("std::move is not needed in Cpp2 - use 'move' parameters/arguments instead", false);
6899-
return {};
6900-
}
6901-
else if (*term.id->identifier == "forward") {
6902-
error("std::forward is not needed in Cpp2 - use 'forward' parameters/arguments instead", false);
6903-
return {};
6904-
}
6905-
first_time_through_loop = false;
6912+
error("std::forward is not needed in Cpp2 - use 'forward' parameters/arguments instead", false);
6913+
return {};
69066914
}
69076915
n->ids.push_back( std::move(term) );
69086916
}

source/sema.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,18 @@ class sema
15111511
}
15121512
}
15131513

1514+
if (
1515+
n.expr->to_string() == "std::move"
1516+
&& n.starts_with_function_call_with_n_parameters(1)
1517+
)
1518+
{
1519+
errors.emplace_back(
1520+
n.position(),
1521+
"std::move(one_argument) is not needed in Cpp2 - use 'move' parameters/arguments instead"
1522+
);
1523+
return false;
1524+
}
1525+
15141526
return true;
15151527
}
15161528

0 commit comments

Comments
 (0)