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

Title: Unbraced function expression template argument not parsed.

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

u: <_: * _> type == std::in_place_t;
t: @struct type = {
  this: u<+:() = i32()>;
}
main: () = { }
Commands:
cppfront main.cpp2
clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -fsanitize=undefined -Werror=unused-result -I . main.cpp

Expected result: A working program.

Actual result and error:

main.cpp2(3,10): error: missing semicolon at end of declaration or equal at start of initializer (at '<')
main.cpp2(2,19): error: ill-formed initializer (at '{')
main.cpp2(2,1): error: unexpected text at end of Cpp2 code section (at 't')
main.cpp2(1,0): error: parse failed for section starting here

JohelEGP avatar Aug 18 '23 01:08 JohelEGP

From #790:

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 31 '23 14:10 JohelEGP