Skip to content

Commit 1943783

Browse files
committed
Corrected order of _template-argument_ productions, see #50
Examples like `f<a+a>` should be parsed as an _expression_ first (if it can be an expression, it is), and then if that fails parsed as an _id-expression_ The original comment was correct about the production order, so put that back to how it was Added a regression test case
1 parent e0df1ee commit 1943783

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include <vector>
22

3-
template<bool>
3+
template<auto>
44
auto f(auto, auto) -> void { }
55

6+
constexpr int a = 1;
7+
68
main: () -> int = {
79
v : std::vector<int> = ( 1, 2, 3 );
810
std::cout << (1+2)*(3+v[0]);
911
f<(1>2)>(3,4);
12+
f< a+a >(5,6);
1013
}

regression-tests/test-results/mixed-test-parens.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
#line 1 "mixed-test-parens.cpp2"
55
#include <vector>
66

7-
template<bool>
7+
template<auto>
88
auto f(auto, auto) -> void { }
99

10+
constexpr int a = 1;
11+
1012
[[nodiscard]] auto main() -> int;
1113

1214
//=== Cpp2 definitions ==========================================================
1315

14-
#line 5 "mixed-test-parens.cpp2"
16+
#line 7 "mixed-test-parens.cpp2"
1517

1618
[[nodiscard]] auto main() -> int{
1719
std::vector<int> v { 1, 2, 3 };
1820
std::cout << (1 + 2) * (3 + v[0]);
1921
f<(1 > 2)>(3, 4);
22+
f< a + a>(5, 6);
2023
}

source/parse.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,8 +1761,8 @@ class parser
17611761
//G template-argument-list , template-argument
17621762
//G
17631763
//G template-argument:
1764-
//G id-expression
17651764
//G expression
1765+
//G id-expression
17661766
//G
17671767
auto unqualified_id() -> std::unique_ptr<unqualified_id_node>
17681768
{
@@ -1804,12 +1804,12 @@ class parser
18041804
unqualified_id_node::term term;
18051805

18061806
do {
1807-
if (auto i = id_expression()) {
1808-
term.arg = std::move(i);
1809-
}
1810-
else if (auto e = expression(false)) { // disallow relational comparisons in template args
1807+
if (auto e = expression(false)) { // disallow unparenthesized relational comparisons in template args
18111808
term.arg = std::move(e);
18121809
}
1810+
else if (auto i = id_expression()) {
1811+
term.arg = std::move(i);
1812+
}
18131813
else {
18141814
back_out_template_arg_list();
18151815
return n;

0 commit comments

Comments
 (0)