Closed
Description
Besides the type
with a requires
, these attempt to forward declare a function expression.
Minimal reproducer (https://godbolt.org/z/b95ha454e):
z: <V: _> type == int;
a: z<:() = { }> = ();
b: <T> type requires :() -> _ = true;() = { }
c: <V: z<:() = { }>> () = { }
d: (_: z<:() = { }>) = { }
Commands:
cppfront x.cpp2
clang++17 -std=c++2b -stdlib=libc++ -I $CPPFRONT_INCLUDE_DIR x.cpp
Expected result: It's not possible in general to forward declare something that requires repeating a lambda in the definition and declaration due to the repeated lambda expressions having different types. See https://compiler-explorer.com/z/GxKcYnhMe. So maybe these uses of a function expression should be banned.
Actual result and error:
Generated Cpp1.
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
#line 4 "/app/main.cpp2"
template<typename T> requires( () )
class b;
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "/app/main.cpp2"
template<auto V> using z = int;
extern z<[]() -> void;
> a; template<typename T> requires( public: []() -> auto;
() )
class b {
public: b() = default;
public: b(b const&) = delete;
public: auto operator=(b const&) -> void = delete;
#line 4 "/app/main.cpp2"
};
template<z<[]() -> void;
> V> auto c() -> void; auto d(cpp2::in<z<[]() -> void;>> _) -> void;
//=== Cpp2 function definitions =================================================
#line 3 "/app/main.cpp2"
z<[]() -> void{}> a {};
template<z<[]() -> void{}> V> auto c() -> void{}
auto d(cpp2::in<z<[]() -> void{}>> _) -> void{}
Many Cpp1 errors.
main.cpp2:4:33: error: expected expression
template<typename T> requires( () )
^
main.cpp2:3:22: error: expected body of lambda expression
extern z<[]() -> void;
^
main.cpp2:3:22: error: expected '>'
main.cpp2:3:9: note: to match this '<'
extern z<[]() -> void;
^
main.cpp2:4:1: error: expected unqualified-id
> a; template<typename T> requires( public: []() -> auto;
^
main.cpp2:4:37: error: expected expression
> a; template<typename T> requires( public: []() -> auto;
^
main.cpp2:5:2: error: expected unqualified-id
() )
^
main.cpp2:5:24: error: expected body of lambda expression
template<z<[]() -> void;
^
main.cpp2:5:24: error: expected '>'
main.cpp2:5:11: note: to match this '<'
template<z<[]() -> void;
^
main.cpp2:5:24: error: expected ',' or '>' in template-parameter-list
template<z<[]() -> void;
^
main.cpp2:5:24: error: declaration does not declare anything
main.cpp2:6:1: error: expected unqualified-id
> V> auto c() -> void; auto d(cpp2::in<z<[]() -> void;>> _) -> void;
^
main.cpp2:6:54: error: expected body of lambda expression
> V> auto c() -> void; auto d(cpp2::in<z<[]() -> void;>> _) -> void;
^
main.cpp2:6:54: error: expected '>'
main.cpp2:6:41: note: to match this '<'
> V> auto c() -> void; auto d(cpp2::in<z<[]() -> void;>> _) -> void;
^
main.cpp2:6:54: error: type name requires a specifier or qualifier
> V> auto c() -> void; auto d(cpp2::in<z<[]() -> void;>> _) -> void;
^
main.cpp2:6:54: error: expected '>'
main.cpp2:6:39: note: to match this '<'
> V> auto c() -> void; auto d(cpp2::in<z<[]() -> void;>> _) -> void;
^
main.cpp2:6:54: error: expected body of lambda expression
> V> auto c() -> void; auto d(cpp2::in<z<[]() -> void;>> _) -> void;
^
main.cpp2:6:54: error: expected '>'
main.cpp2:6:41: note: to match this '<'
> V> auto c() -> void; auto d(cpp2::in<z<[]() -> void;>> _) -> void;
^
main.cpp2:6:54: error: type name requires a specifier or qualifier
> V> auto c() -> void; auto d(cpp2::in<z<[]() -> void;>> _) -> void;
^
main.cpp2:6:54: error: expected '>'
main.cpp2:6:39: note: to match this '<'
> V> auto c() -> void; auto d(cpp2::in<z<[]() -> void;>> _) -> void;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
Other observations: Now is #472.