hsutter / cppfront

A personal experimental C++ Syntax 2 -> Syntax 1 compiler
Other
5.39k stars 232 forks source link

[BUG] NTTP can't be variadic or unnamed #877

Closed JohelEGP closed 7 months ago

JohelEGP commented 8 months ago

Title: NTTP can't be variadic or unnamed.

Minimal reproducer (https://cpp2.godbolt.org/z/rdb6dbvv1):

t: @struct <_...: _> type = {
  f: <_: int> () -> i32 = 0;
}
main: () = { }

Commands: ```bash cppfront main.cpp2 clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value -Werror=unused-parameter -I . main.cpp ```

Expected result:

  1. 812 for NTTPs.

  2. f6ecbb4349e3f477205c68c87c3a17a52688ff9c for NTTPs.

Actual result and error:

template<auto _> class t {
  public: template<int _> [[nodiscard]] static auto f() -> cpp2::i32;
};

Cpp2 lowered to Cpp1: ```C++ //=== Cpp2 type declarations ==================================================== #include "cpp2util.h" #line 1 "/app/example.cpp2" template class t; #line 2 "/app/example.cpp2" //=== Cpp2 type definitions and function declarations =========================== #line 1 "/app/example.cpp2" template class t { #line 2 "/app/example.cpp2" public: template [[nodiscard]] static auto f() -> cpp2::i32; }; auto main() -> int; //=== Cpp2 function definitions ================================================= #line 1 "/app/example.cpp2" #line 2 "/app/example.cpp2" template template [[nodiscard]] auto t<_>::f() -> cpp2::i32 { return 0; } auto main() -> int{} ```

Output:

main.cpp2:2:24: error: declaration of '_' shadows template parameter
    2 |   public: template<int _> [[nodiscard]] static auto f() -> cpp2::i32;
      |                        ^
main.cpp2:1:15: note: template parameter is declared here
    1 | template<auto _> class t {
      |               ^

See also: