Skip to content

Commit a330403

Browse files
committed
Fix parse for non-first argument named out, move, or forward
Closes #1156
1 parent 2ea1950 commit a330403

File tree

5 files changed

+23
-29
lines changed

5 files changed

+23
-29
lines changed

docs/cpp2/objects.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,16 @@ In the above example, note the simple rule for branches: The local variable must
101101

102102
## <a id="heap"></a>Heap objects
103103

104-
Objects can also be allocated on the heap using `#!cpp arena.new <T> (/*initializer, arguments*/)` where `arena` is any object that acts as a memory arena and provides a `#!cpp .new` function template. Two memory arena objects are provided in namespace `cpp2`:
104+
Objects can also be allocated on the heap using `#!cpp xxx.new <T> (/*initializer, arguments*/)` where `xxx` is any object that acts as a memory allocator and provides a `#!cpp .new` function template. Two memory allocators objects are provided in namespace `cpp2`:
105105

106106
- `#!cpp unique.new<T>` calls `std::make_unique<T>` and returns a `std::unique_ptr<T>`.
107107

108108
- `#!cpp shared.new<T>` calls `std::make_shared<T>` and returns a `std::shared_ptr<T>`.
109109

110-
The default is `#!cpp unique.new` if you don't specify an arena object.
110+
The default is `#!cpp unique.new` if you don't specify an allocator object.
111111

112112
For example (see [types](types.md) for more details about writing types):
113113

114-
115114
``` cpp title="Heap allocation" hl_lines="3-6 10-11"
116115
f: () -> std::shared_ptr<widget>
117116
= {

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.0 Build 9711:1018
2+
cppfront compiler v0.7.0 Build 9712:0834
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-
"9711:1018"
1+
"9712:0834"

source/lex.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,7 @@ auto lex_line(
935935
//G simple-hexadecimal-digit-sequence hexadecimal-digit
936936
//G
937937
//G hexadecimal-escape-sequence:
938-
//G '\x' hexadecimal-digit
939-
//G hexadecimal-escape-sequence hexadecimal-digit
938+
//G '\x' simple-hexadecimal-digit-sequence
940939
//G '\x{' simple-hexadecimal-digit-sequence '}'
941940
//G
942941
auto peek_is_hexadecimal_escape_sequence = [&](int offset)

source/parse.h

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6485,19 +6485,24 @@ class parser
64856485
n->open_paren = open_paren;
64866486
n->inside_initializer = inside_initializer;
64876487

6488-
if (auto dir = to_passing_style(curr());
6489-
(
6490-
dir == passing_style::out
6491-
|| dir == passing_style::move
6492-
|| dir == passing_style::forward
6488+
auto consume_optional_passing_style = [&] {
6489+
pass = passing_style::in;
6490+
if (auto dir = to_passing_style(curr());
6491+
(
6492+
dir == passing_style::out
6493+
|| dir == passing_style::move
6494+
|| dir == passing_style::forward
6495+
)
6496+
&& peek(1)
6497+
&& peek(1)->type() == lexeme::Identifier
64936498
)
6494-
&& peek(1)
6495-
&& peek(1)->type() == lexeme::Identifier
6496-
)
6497-
{
6498-
pass = dir;
6499-
next();
6500-
}
6499+
{
6500+
pass = dir;
6501+
next();
6502+
}
6503+
};
6504+
6505+
consume_optional_passing_style();
65016506
auto x = expression();
65026507

65036508
// If this is an empty expression_list, we're done
@@ -6516,16 +6521,7 @@ class parser
65166521
break;
65176522
}
65186523

6519-
pass = passing_style::in;
6520-
if (auto dir = to_passing_style(curr());
6521-
dir == passing_style::out
6522-
|| dir == passing_style::move
6523-
|| dir == passing_style::forward
6524-
)
6525-
{
6526-
pass = dir;
6527-
next();
6528-
}
6524+
consume_optional_passing_style();
65296525
auto expr = expression();
65306526
if (!expr) {
65316527
error("invalid text in expression list", true, {}, true);

0 commit comments

Comments
 (0)