Skip to content

Commit 0955521

Browse files
committed
Name clash for unamed template arguments.
1 parent 930e70a commit 0955521

File tree

3 files changed

+38
-43
lines changed

3 files changed

+38
-43
lines changed
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
pure2-variadics.cpp2:21:10: error: ‘R’ has not been declared
2-
pure2-variadics.cpp2:17:20: error: declaration of template parameter ‘T’ shadows template parameter
3-
pure2-variadics.cpp2:16:10: note: template parameter ‘T’ declared here
4-
pure2-variadics.cpp2:21:10: error: ‘R’ has not been declared
5-
pure2-variadics.cpp2:27:20: error: declaration of template parameter ‘_’ shadows template parameter
6-
pure2-variadics.cpp2:26:10: note: template parameter ‘_’ declared here
7-
pure2-variadics.cpp2:17:33: error: declaration of template parameter ‘T’ shadows template parameter
8-
pure2-variadics.cpp2:17:13: note: template parameter ‘T’ declared here
9-
pure2-variadics.cpp2:17:63: error: expansion pattern ‘T’ contains no parameter packs
10-
pure2-variadics.cpp2:17:66: error: template argument 1 is invalid
11-
pure2-variadics.cpp2:17:59: error: too many template-parameter-lists
12-
pure2-variadics.cpp2:22:13: error: ‘R’ has not been declared
13-
pure2-variadics.cpp2:22:60: error: expansion pattern ‘_’ contains no parameter packs
14-
pure2-variadics.cpp2:22:63: error: template argument 1 is invalid
15-
pure2-variadics.cpp2:22:56: error: too many template-parameter-lists
16-
pure2-variadics.cpp2:27:33: error: declaration of template parameter ‘_’ shadows template parameter
17-
pure2-variadics.cpp2:27:13: note: template parameter ‘_’ declared here
18-
pure2-variadics.cpp2:27:63: error: expansion pattern ‘_’ contains no parameter packs
19-
pure2-variadics.cpp2:27:66: error: template argument 1 is invalid
20-
pure2-variadics.cpp2:27:59: error: too many template-parameter-lists
1+
pure2-variadics.cpp2:17:20: error: declaration of template parameter ‘UnnamedTypeParam1’ shadows template parameter
2+
pure2-variadics.cpp2:16:10: note: template parameter ‘UnnamedTypeParam1’ declared here
3+
pure2-variadics.cpp2:27:20: error: declaration of template parameter ‘UnnamedTypeParam1’ shadows template parameter
4+
pure2-variadics.cpp2:26:10: note: template parameter ‘UnnamedTypeParam1’ declared here
5+
pure2-variadics.cpp2:17:53: error: declaration of template parameter ‘UnnamedTypeParam1’ shadows template parameter
6+
pure2-variadics.cpp2:17:13: note: template parameter ‘UnnamedTypeParam1’ declared here
7+
pure2-variadics.cpp2:17:98: error: ‘_’ was not declared in this scope
8+
pure2-variadics.cpp2:17:99: error: expected parameter pack before ‘...’
9+
pure2-variadics.cpp2:17:102: error: template argument 1 is invalid
10+
pure2-variadics.cpp2:17:95: error: too many template-parameter-lists
11+
pure2-variadics.cpp2:27:49: error: declaration of template parameter ‘UnnamedTypeParam1’ shadows template parameter
12+
pure2-variadics.cpp2:27:13: note: template parameter ‘UnnamedTypeParam1’ declared here
13+
pure2-variadics.cpp2:27:94: error: ‘_’ was not declared in this scope
14+
pure2-variadics.cpp2:27:95: error: expected parameter pack before ‘...’
15+
pure2-variadics.cpp2:27:98: error: template argument 1 is invalid
16+
pure2-variadics.cpp2:27:91: error: too many template-parameter-lists

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ template<typename ...Ts> class x;
1616
template<int ...Ts> class y;
1717

1818
#line 16 "pure2-variadics.cpp2"
19-
template<typename ...UnnamedTypeParam1> class t0;
19+
template<typename ...UnnamedTypeParam1_16_14> class t0;
2020

2121

2222
#line 21 "pure2-variadics.cpp2"
2323
template<auto ...T> class t1;
2424

2525

2626
#line 26 "pure2-variadics.cpp2"
27-
template<auto ...UnnamedTypeParam1> class t2;
27+
template<auto ...UnnamedTypeParam1_26_14> class t2;
2828

2929

3030
//=== Cpp2 type definitions and function declarations ===========================
@@ -56,18 +56,18 @@ template<int ...Ts> class y {
5656
};
5757

5858
// Discard type name pack expansion
59-
template<typename ...UnnamedTypeParam1> class t0 {
60-
public: template<int UnnamedTypeParam1> [[nodiscard]] static auto f() -> cpp2::i32;
59+
template<typename ...UnnamedTypeParam1_16_14> class t0 {
60+
public: template<int UnnamedTypeParam1_17_7> [[nodiscard]] static auto f() -> cpp2::i32;
6161
};
6262

6363
// Discard template type pack expansion
6464
template<auto ...T> class t1 {
65-
public: template<int UnnamedTypeParam1> [[nodiscard]] static auto f() -> cpp2::i32;
65+
public: template<int UnnamedTypeParam1_22_7> [[nodiscard]] static auto f() -> cpp2::i32;
6666
};
6767

6868
// Discard typename and template type pack expansion
69-
template<auto ...UnnamedTypeParam1> class t2 {
70-
public: template<int UnnamedTypeParam1> [[nodiscard]] static auto f() -> cpp2::i32;
69+
template<auto ...UnnamedTypeParam1_26_14> class t2 {
70+
public: template<int UnnamedTypeParam1_27_7> [[nodiscard]] static auto f() -> cpp2::i32;
7171
};
7272

7373
template<typename ...Args> auto left_fold_print(std::ostream& out, Args const& ...args) -> void;
@@ -93,13 +93,13 @@ auto main() -> int;
9393
template <int ...Ts> [[nodiscard]] auto y<Ts...>::func() -> auto { return (0 + ... + Ts); }
9494

9595
#line 17 "pure2-variadics.cpp2"
96-
template <typename ...UnnamedTypeParam1> template<int UnnamedTypeParam1> [[nodiscard]] auto t0<_...>::f() -> cpp2::i32 { return 0; }
96+
template <typename ...UnnamedTypeParam1_16_14> template<int UnnamedTypeParam1_17_7> [[nodiscard]] auto t0<_...>::f() -> cpp2::i32 { return 0; }
9797

9898
#line 22 "pure2-variadics.cpp2"
99-
template <auto ...T> template<int UnnamedTypeParam1> [[nodiscard]] auto t1<T...>::f() -> cpp2::i32 { return 0; }
99+
template <auto ...T> template<int UnnamedTypeParam1_22_7> [[nodiscard]] auto t1<T...>::f() -> cpp2::i32 { return 0; }
100100

101101
#line 27 "pure2-variadics.cpp2"
102-
template <auto ...UnnamedTypeParam1> template<int UnnamedTypeParam1> [[nodiscard]] auto t2<_...>::f() -> cpp2::i32 { return 0; }
102+
template <auto ...UnnamedTypeParam1_26_14> template<int UnnamedTypeParam1_27_7> [[nodiscard]] auto t2<_...>::f() -> cpp2::i32 { return 0; }
103103

104104
#line 30 "pure2-variadics.cpp2"
105105
template<typename ...Args> auto left_fold_print(std::ostream& out, Args const& ...args) -> void{

source/to_cpp1.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4262,9 +4262,8 @@ class cppfront
42624262
//-----------------------------------------------------------------------
42634263
// Handle type parameters
42644264

4265-
if (n.declaration->is_type()) {
4266-
assert( is_template_parameter );
4267-
printer.print_cpp2("typename ", identifier_pos);
4265+
// Common template naming
4266+
auto emit_template_name = [&]() {
42684267
if (n.declaration->is_variadic) {
42694268
printer.print_cpp2(
42704269
"...",
@@ -4273,12 +4272,19 @@ class cppfront
42734272
}
42744273

42754274
if (identifier == "_") {
4276-
printer.print_cpp2( "UnnamedTypeParam" + std::to_string(n.ordinal), identifier_pos );
4275+
printer.print_cpp2( "UnnamedTypeParam" + std::to_string(n.ordinal) + "_"
4276+
+ labelized_position(n.declaration->identifier->get_token()),
4277+
identifier_pos );
42774278
}
42784279
else {
42794280
printer.print_cpp2( identifier, identifier_pos );
42804281
}
4282+
};
4283+
if (n.declaration->is_type()) {
4284+
assert( is_template_parameter );
4285+
printer.print_cpp2("typename ", identifier_pos);
42814286

4287+
emit_template_name();
42824288
return;
42834289
}
42844290

@@ -4291,15 +4297,8 @@ class cppfront
42914297
if (is_template_parameter) {
42924298
emit( type_id );
42934299
printer.print_cpp2(" ", type_id.position());
4294-
if (n.declaration->is_variadic) {
4295-
printer.print_cpp2("...",identifier_pos);
4296-
}
4297-
if (identifier == "_") {
4298-
printer.print_cpp2( "UnnamedTypeParam" + std::to_string(n.ordinal), identifier_pos );
4299-
}
4300-
else {
4301-
printer.print_cpp2( identifier, identifier_pos );
4302-
}
4300+
4301+
emit_template_name();
43034302
return;
43044303
}
43054304

0 commit comments

Comments
 (0)