cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[BUG] _template-id_ with anonymous argument not parsed as such

Open JohelEGP opened this issue 2 years ago • 1 comments
trafficstars

Title: template-id with anonymous argument not parsed as such.

Description:

My guess is that it breaks the code to determine whether < is an operator. _ = std::integral_constant<int, :int = 0>(); will error with main.cpp2(3,33): error: invalid statement encountered inside a compound-statement (at ',').

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

f: (_) = { }
main: () = {
  _ = f(std::integral_constant<int, :int = 0>());
}
Commands:
cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp

Expected result: Same as using 0 instead of :int = 0.

Actual result and error: static_cast<void>(f(cpp2::cmp_less(std::integral_constant,int), int{cpp2::cmp_greater(0,())}));.

Cpp2 lowered to Cpp1:


//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"



//=== Cpp2 type definitions and function declarations ===========================

auto f([[maybe_unused]] auto const& param1) -> void;
auto main() -> int;
  

//=== Cpp2 function definitions =================================================

auto f([[maybe_unused]] auto const& param1) -> void{}
auto main() -> int{
  static_cast<void>(f(cpp2::cmp_less(std::integral_constant,int), int{cpp2::cmp_greater(0,())}));
}
Output:
build/main.cpp:20:60: error: expected '(' for function-style cast or type construction
   20 |   static_cast<void>(f(cpp2::cmp_less(std::integral_constant,int), int{cpp2::cmp_greater(0,())}));
      |                                      ~~~~~~~~~~~~~~~~~~~~~~^
build/main.cpp:20:64: error: expected '(' for function-style cast or type construction
   20 |   static_cast<void>(f(cpp2::cmp_less(std::integral_constant,int), int{cpp2::cmp_greater(0,())}));
      |                                                             ~~~^
build/main.cpp:20:92: error: expected expression
   20 |   static_cast<void>(f(cpp2::cmp_less(std::integral_constant,int), int{cpp2::cmp_greater(0,())}));
      |                                                                                            ^
3 errors generated.

JohelEGP avatar Oct 29 '23 14:10 JohelEGP