[BUG] Constructor with 1 parameter create 2 différentes Cpp1 functions
When I have a constructor with 1 parameter in Cpp2, a constructor and an operator= are created in Cpp1 and which don't do exactly the same thing, which leads to a compilation error.
This Cpp2 code:
Engine:<Size: i8> type = {
//...
public operator=:(out this, playAtariGo: bool) = {
iterations = 0;
state: State<Stone, Size> = ();
states.push_back(state);
useAtariGoRules = playAtariGo;
}
//...
}
Give this 2 methods in Cpp1:
#line 26 "../cpp2/engine.h2"
template <cpp2::i8 Size> Engine<Size>::Engine(cpp2::impl::in<bool> playAtariGo){
iterations = 0;
State<Stone,Size> state {};
CPP2_UFCS(push_back)(states, cpp2::move(state));
useAtariGoRules = playAtariGo;
}
#line 26 "../cpp2/engine.h2"
template <cpp2::i8 Size> auto Engine<Size>::operator=(cpp2::impl::in<bool> playAtariGo) -> Engine& {
goban = {};
moves = {};
states = {};
blackPoint = 0;
whitePoint = 0;
useAtariGoRules = false;
numberOfCapturesToWin = 1;
blackStonesCaptured = 0;
whiteStonesCaptured = 0;
#line 27 "../cpp2/engine.h2"
iterations = 0;
State<Stone,Size> state {};
CPP2_UFCS(push_back)(states, cpp2::move(state));
useAtariGoRules = playAtariGo;
return *this;
#line 31 "../cpp2/engine.h2"
}
-
First question: Why do I have an
operator=in Cpp1 when I didn't use theimplicitkeyword? -
Second question: Why are the implementations of the 2 methods not strictly identical?
In my case the Cpp1 constrctor is correct but the Cpp1
operator=leads to the following error:
./cpp2/engine.h2:27:15: error: overload resolution selected deleted operator '='
27 | goban = {};
| ~~~~~ ^ ~~
Hello, for fist question as far as I see this is default behavior :
out this: Writing operator=: (out this /.../ ) is naturally both a constructor and an assignment operator, because an out parameter can take an uninitialized or initialized argument. If you don't also write a more-specialized inout this assignment operator, Cpp2 will use the out this function also for assignment.
For second question I don't know what's happening there... (skill issue 😄, still a beginner in cppfront). This is probably to ensure that unused variables are initialized since *this is returned. Also it seems that for some reason the error is generated because of explicitly deleted operator= for whatever delctype(goban) is. (I know that the error says that 😂)
Btw I don't know if there is a difference between your version of cppfront and the one on compiler explorer or the code is generated differently for .h2 files but I cannot reproduce this.