Skip to content

[BUG] @basic_value default constructor is not implicit #553

Closed
@JohelEGP

Description

@JohelEGP

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{}
Output:
main.cpp2:5:37: error: no viable overloaded '='
    5 |                                   a = {};
      |                                   ~ ^ ~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions