Closed
Description
Title: Variable with placeholder type can't share name with member call in initializer.
Description:
Something in the UFCS machinery breaks this use case.
My actual use case looks more like this (https://cpp2.godbolt.org/z/sGK36zbe1):
f := :() = {
v&$*.f();
};
It's a function expression that captures.
Using std::function
is undesirable,
and currently impossible given #343.
Minimal reproducer (https://cpp2.godbolt.org/z/r7Ef84MKs):
t: type = {
f: (this) -> i32 = 0;
}
main: () = {
f := t().f();
}
Commands:
cppfront main.cpp2
clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -I . main.cpp
Expected result: A working program.
Actual result and error:
Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
class t;
//=== Cpp2 type definitions and function declarations ===========================
class t {
public: [[nodiscard]] auto f() const -> cpp2::i32;
public: t() = default;
public: t(t const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(t const&) -> void = delete;
};
auto main() -> int;
//=== Cpp2 function definitions =================================================
[[nodiscard]] auto t::f() const -> cpp2::i32 { return 0; }
auto main() -> int{
auto f {CPP2_UFCS_0(f, t())};
}
main.cpp2:5:23: error: variable 'f' declared with deduced type 'auto' cannot appear in its own initializer
5 | auto f {CPP2_UFCS_0(f, t())};
| ^
1 error generated.