Closed
Description
Title: @basic_value
default constructor is not implicit
.
Description:
We expect a value to be assignable from an empty argument list, like x = ()
.
Minimal reproducer (https://cpp2.godbolt.org/z/ahM4Pcdbq):
t: @basic_value type = { }
u: type = {
a: t = ();
operator=: (out this, x: i32) = _ = x;
}
main: () = { }
Commands:
cppfront main.cpp2
clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -I . main.cpp
Expected result: public: t();
Actual result and error: public: explicit t();
Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
class t;
class u;
//=== Cpp2 type definitions and function declarations ===========================
class t {
public: t(t const& that);
public: auto operator=(t const& that) -> t& ;
public: t(t&& that) noexcept;
public: auto operator=(t&& that) noexcept -> t& ;
public: explicit t();
};
class u {
private: t a {};
public: explicit u(cpp2::in<cpp2::i32> x);
public: auto operator=(cpp2::in<cpp2::i32> x) -> u& ;
public: u(u const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(u const&) -> void = delete;
};
auto main() -> int;
//=== Cpp2 function definitions =================================================
t::t(t const& that){}
auto t::operator=(t const& that) -> t& {
return *this;}
t::t(t&& that) noexcept{}
auto t::operator=(t&& that) noexcept -> t& {
return *this;}
t::t(){}
u::u(cpp2::in<cpp2::i32> x) { (void) x; }
auto u::operator=(cpp2::in<cpp2::i32> x) -> u& {
a = {};
(void) x;
return *this;
}
auto main() -> int{}
main.cpp2:5:37: error: no viable overloaded '='
5 | a = {};
| ~ ^ ~~