Skip to content

Commit 0d79a3b

Browse files
committed
Bugfix for missing semaphore in typed template parameters.
1 parent 5a032d7 commit 0d79a3b

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

regression-tests/pure2-variadics.cpp2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ x: <Ts...: type> type = {
66
func: () = {}
77
}
88

9+
// int pack expansion
10+
y: <Ts...: int> type = {
11+
12+
func: () ( 0 + ... + Ts);
13+
}
14+
915
left_fold_print: <Args...: type> (inout out: std::ostream, args...: Args) = {
1016
// Binary left fold expression
1117
(out << ... << args);
@@ -31,4 +37,6 @@ main: ()
3137

3238
std::cout << "\nfirst all() returned (all(true, true, true, false))$";
3339
std::cout << "\nsecond all() returned " << all(true, true, true, true) as std::string;
40+
41+
std::cout << "\nsum of (1, 2, 3, 100) is: " << y<1,2,3,100>().func() as std::string;
3442
}

regression-tests/test-results/gcc-13/pure2-variadics.cpp.execution

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ plu
33
abr
44
3.14word-1500
55
first all() returned false
6-
second all() returned true
6+
second all() returned true
7+
sum of (1, 2, 3, 100) is: 106

regression-tests/test-results/pure2-variadics.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
template<typename ...Ts> class x;
1313

1414

15+
#line 10 "pure2-variadics.cpp2"
16+
template<int ...Ts> class y;
17+
18+
1519
//=== Cpp2 type definitions and function declarations ===========================
1620

1721
#line 1 "pure2-variadics.cpp2"
@@ -29,12 +33,23 @@ template<typename ...Ts> class x {
2933
#line 7 "pure2-variadics.cpp2"
3034
};
3135

36+
// int pack expansion
37+
template<int ...Ts> class y {
38+
39+
public: [[nodiscard]] static auto func() -> auto;
40+
public: y() = default;
41+
public: y(y const&) = delete; /* No 'that' constructor, suppress copy */
42+
public: auto operator=(y const&) -> void = delete;
43+
44+
#line 13 "pure2-variadics.cpp2"
45+
};
46+
3247
template<typename ...Args> auto left_fold_print(std::ostream& out, Args const& ...args) -> void;
3348

34-
#line 14 "pure2-variadics.cpp2"
49+
#line 20 "pure2-variadics.cpp2"
3550
template<typename ...Args> [[nodiscard]] auto all(Args const& ...args) -> bool;
3651

37-
#line 18 "pure2-variadics.cpp2"
52+
#line 24 "pure2-variadics.cpp2"
3853
template <typename ...Args> [[nodiscard]] auto make_string(Args&& ...args) -> auto;
3954

4055
template <typename T, typename ...Args> [[nodiscard]] auto make(Args&& ...args) -> auto;
@@ -48,7 +63,10 @@ auto main() -> int;
4863
#line 6 "pure2-variadics.cpp2"
4964
template <typename ...Ts> auto x<Ts...>::func() -> void{}
5065

51-
#line 9 "pure2-variadics.cpp2"
66+
#line 12 "pure2-variadics.cpp2"
67+
template <int ...Ts> [[nodiscard]] auto y<Ts...>::func() -> auto { return (0 + ... + Ts); }
68+
69+
#line 15 "pure2-variadics.cpp2"
5270
template<typename ...Args> auto left_fold_print(std::ostream& out, Args const& ...args) -> void{
5371
// Binary left fold expression
5472
(out << ... << args);
@@ -64,7 +82,7 @@ template <typename T, typename ...Args> [[nodiscard]] auto make(Args&& ...args)
6482

6583
auto main() -> int
6684
{
67-
x<int,long,std::string> auto_24_5 {};
85+
x<int,long,std::string> auto_30_5 {};
6886

6987
std::cout << std::string("xyzzy", 3) << "\n";
7088
std::cout << make_string("plugh", cpp2::u8{3}) << "\n";
@@ -74,5 +92,7 @@ auto main() -> int
7492

7593
std::cout << "\nfirst all() returned " + cpp2::to_string(all(true, true, true, false));
7694
std::cout << "\nsecond all() returned " << cpp2::as_<std::string>(all(true, true, true, true));
95+
96+
std::cout << "\nsum of (1, 2, 3, 100) is: " << cpp2::as_<std::string>(CPP2_UFCS(func)(y<1,2,3,100>()));
7797
}
7898

source/to_cpp1.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4291,7 +4291,10 @@ class cppfront
42914291
if (is_template_parameter) {
42924292
emit( type_id );
42934293
printer.print_cpp2(" ", type_id.position());
4294-
printer.print_cpp2( identifier, identifier_pos );
4294+
if (n.declaration->is_variadic) {
4295+
printer.print_cpp2("...",identifier_pos);
4296+
}
4297+
printer.print_cpp2( identifier, identifier_pos );
42954298
return;
42964299
}
42974300

0 commit comments

Comments
 (0)