Repository navigation
[BUG] Support _ unnamed template parameter. #812
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Title: Support _ unnamed template parameter.
Description:
Commit 6ce2643 added support only for function parameters.
Minimal reproducer (https://cpp2.godbolt.org/z/WY56cMoTd):
f: <_, _> (_, _) = { }
main: () = { }
Commands:
cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cppExpected result:
The template parameters to be named similar to the function parameters.
template<typename tparam1, typename tparam2> auto f([[maybe_unused]] auto const& param1, [[maybe_unused]] auto const& param2) -> void;Actual result and error:
template<typename _, typename _> auto f([[maybe_unused]] auto const& param1, [[maybe_unused]] auto const& param2) -> void;Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
//=== Cpp2 type definitions and function declarations ===========================
template<typename _, typename _> auto f([[maybe_unused]] auto const& param1, [[maybe_unused]] auto const& param2) -> void;
auto main() -> int;
//=== Cpp2 function definitions =================================================
template<typename _, typename _> auto f([[maybe_unused]] auto const& param1, [[maybe_unused]] auto const& param2) -> void{}
auto main() -> int{}Output:
build/main.cpp:12:31: error: declaration of '_' shadows template parameter
12 | template<typename _, typename _> auto f([[maybe_unused]] auto const& param1, [[maybe_unused]] auto const& param2) -> void;
| ^
build/main.cpp:12:19: note: template parameter is declared here
12 | template<typename _, typename _> auto f([[maybe_unused]] auto const& param1, [[maybe_unused]] auto const& param2) -> void;
| ^
build/main.cpp:18:31: error: declaration of '_' shadows template parameter
18 | template<typename _, typename _> auto f([[maybe_unused]] auto const& param1, [[maybe_unused]] auto const& param2) -> void{}
| ^
build/main.cpp:18:19: note: template parameter is declared here
18 | template<typename _, typename _> auto f([[maybe_unused]] auto const& param1, [[maybe_unused]] auto const& param2) -> void{}
| ^
2 errors generated.
See also:
- Commit 6ce2643.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
gregmarr commentedon Nov 9, 2023
I'm curious what the use case is for unused template parameters. Is it for specializing an existing template?
JohelEGP commentedon Nov 9, 2023
Compilers don't seem to warn on these.
But I have to invent names,
and maybe I'll run out of T, U, V, W, ???.
Of course, this mostly happens in tests.
gregmarr commentedon Nov 9, 2023
Okay, thanks.
hsutter commentedon Nov 10, 2023
Thanks!
JohelEGP commentedon Nov 24, 2023
This is now #877.
Repeat of #877
It doesn't work for NTTPs: https://cpp2.godbolt.org/z/rdb6dbvv1.
Also,
<_...: _>doesn't lower to a parameter pack declaration.Support `_` unnamed type parameters - closes hsutter#812
Support `_` unnamed type parameters - closes hsutter#812