Skip to content

Commit b6ffa69

Browse files
authored
fix(parse): add missing condition for "inside initializer" (#599)
* fix(parse): add missing condition for "inside initializer" * test: use the test case from #597
1 parent 720835b commit b6ffa69

6 files changed

+47
-4
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
u: type == std::array<i32, 2>;
2+
t: @struct type = {
3+
this: std::integral_constant<u, :u = (17, 29)>;
4+
}
5+
main: () = {
6+
[[assert Testing: t::value[0] == 17]]
7+
[[assert Testing: t::value[1] == 29]]
8+
}

regression-tests/test-results/clang-18/pure2-bugfix-for-non-local-initialization.cpp.execution

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-bugfix-for-non-local-initialization.cpp.output

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
10+
#line 2 "pure2-bugfix-for-non-local-initialization.cpp2"
11+
class t;
12+
13+
14+
//=== Cpp2 type definitions and function declarations ===========================
15+
16+
#line 1 "pure2-bugfix-for-non-local-initialization.cpp2"
17+
using u = std::array<cpp2::i32,2>;
18+
class t: public std::integral_constant<u,u{17, 29}> {
19+
20+
};
21+
auto main() -> int;
22+
23+
24+
//=== Cpp2 function definitions =================================================
25+
26+
27+
#line 5 "pure2-bugfix-for-non-local-initialization.cpp2"
28+
auto main() -> int{
29+
cpp2::Testing.expects(cpp2::assert_in_bounds(t::value, 0)==17, "");
30+
cpp2::Testing.expects(cpp2::assert_in_bounds(t::value, 1)==29, "");
31+
}
32+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-non-local-initialization.cpp2... ok (all Cpp2, passes safety checks)
2+

source/parse.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,6 +4161,7 @@ class parser
41614161
curr().type() != lexeme::Semicolon
41624162
&& curr().type() != lexeme::RightParen
41634163
&& curr().type() != lexeme::RightBracket
4164+
&& curr().type() != lexeme::Greater
41644165
&& curr().type() != lexeme::Comma
41654166
) {
41664167
expr_list->inside_initializer = false;
@@ -5031,20 +5032,20 @@ class parser
50315032
}
50325033
return expression(false); // false == disallow unparenthesized relational comparisons in template args
50335034
}()
5034-
)
5035+
)
50355036
{
50365037
term.arg = std::move(e);
50375038
}
5038-
5039+
50395040
// Else try parsing it as a type id
50405041
else if (auto i = type_id()) {
50415042
term.arg = std::move(i);
50425043
}
5043-
5044+
50445045
else {
50455046
break;
50465047
}
5047-
5048+
50485049
n->template_args.push_back( std::move(term) );
50495050
}
50505051
// Use the lambda trick to jam in a "next" clause

0 commit comments

Comments
 (0)