﻿id	summary	reporter	owner	description	type	status	priority	component	version	resolution	keywords	cc
197	Generated constructor calls copy ctor twice on tuple elements	f37yu		"Compiler generated copy constructor for struct with fields of tuple type does a redundant copy.

The tuple elements are first copied to generated temporary variables, then to the actual destination.

Code that creates the problem:


{{{
struct A {};
void ?{}(A& a) { sout | 'A'; }
struct B { [A, A] elem; };

int main() {
  B b;
  sout | '\n';
  B b1 = b;
}
}}}

Correct behavior is the program prints two A's twice. Currently on B b1 = b; it prints four times.

compile this snippet with -n -P resolver, should find the following (note the ""maybe constructed""):

{{{
?{}: autogenerated cfa static inline function
... with parameters
  _dst: reference to instance of struct B with body 1
  _src: instance of struct B with body 1
... returning nothing
... with body
  CompoundStmt
    Implicit Ctor Dtor Statement
    ... with Ctor/Dtor: Expression Statement:
        Tuple Assignment Expression, with stmt expr:
          Statement Expression: 
            CompoundStmt
              Declaration of __multassign_L0: reference to instance of struct A with body 1 with initializer (not constructed)
                Simple Initializer: Generated Cast of:
                  Tuple Index Expression, with tuple:
                    Member Expression, with field:
                      elem: tuple of types
                        instance of struct A with body 1
                        instance of struct A with body 1

                    ... from aggregate:
                      Generated Cast of:
                        Variable Expression: _dst: reference to instance of struct B with body 1
                      ... to:
                        instance of struct B with body 1                    with index: 0

                ... to:
                  reference to instance of struct A with body 1

              Declaration of __multassign_L1: reference to instance of struct A with body 1 with initializer (not constructed)
                Simple Initializer: Generated Cast of:
                  Tuple Index Expression, with tuple:
                    Member Expression, with field:
                      elem: tuple of types
                        instance of struct A with body 1
                        instance of struct A with body 1

                    ... from aggregate:
                      Generated Cast of:
                        Variable Expression: _dst: reference to instance of struct B with body 1
                      ... to:
                        instance of struct B with body 1                    with index: 1

                ... to:
                  reference to instance of struct A with body 1

              Declaration of __multassign_R0: instance of struct A with body 1 with initializer (maybe constructed)
                Constructor initializer: 
                ... initially constructed with Implicit Ctor Dtor Statement
                  ... with Ctor/Dtor: Expression Statement:
                      Application of
                        Variable Expression: ?{}: static inline function
                        ... with parameters
                          _dst: reference to instance of struct A with body 1
                          _src: instance of struct A with body 1
                        ... returning nothing

                      ... to arguments
                        Generated Cast of:
                          Variable Expression: __multassign_R0: instance of struct A with body 1
                        ... to:
                          reference to instance of struct A with body 1
                        Tuple Index Expression, with tuple:
                          Member Expression, with field:
                            elem: tuple of types
                              instance of struct A with body 1
                              instance of struct A with body 1

                          ... from aggregate:
                            Variable Expression: _src: instance of struct B with body 1                          with index: 0


                ... destructed with Implicit Ctor Dtor Statement
                  ... with Ctor/Dtor: Expression Statement:
                      Application of
                        Variable Expression: ^?{}: static inline function
                        ... with parameters
                          _dst: reference to instance of struct A with body 1
                        ... returning nothing

                      ... to arguments
                        Generated Cast of:
                          Variable Expression: __multassign_R0: instance of struct A with body 1
                        ... to:
                          reference to instance of struct A with body 1



              Declaration of __multassign_R1: instance of struct A with body 1 with initializer (maybe constructed)
                Constructor initializer: 
                ... initially constructed with Implicit Ctor Dtor Statement
                  ... with Ctor/Dtor: Expression Statement:
                      Application of
                        Variable Expression: ?{}: static inline function
                        ... with parameters
                          _dst: reference to instance of struct A with body 1
                          _src: instance of struct A with body 1
                        ... returning nothing

                      ... to arguments
                        Generated Cast of:
                          Variable Expression: __multassign_R1: instance of struct A with body 1
                        ... to:
                          reference to instance of struct A with body 1
                        Tuple Index Expression, with tuple:
                          Member Expression, with field:
                            elem: tuple of types
                              instance of struct A with body 1
                              instance of struct A with body 1

                          ... from aggregate:
                            Variable Expression: _src: instance of struct B with body 1                          with index: 1


                ... destructed with Implicit Ctor Dtor Statement
                  ... with Ctor/Dtor: Expression Statement:
                      Application of
                        Variable Expression: ^?{}: static inline function
                        ... with parameters
                          _dst: reference to instance of struct A with body 1
                        ... returning nothing

                      ... to arguments
                        Generated Cast of:
                          Variable Expression: __multassign_R1: instance of struct A with body 1
                        ... to:
                          reference to instance of struct A with body 1



              Expression Statement:
                Tuple:
                  Application of
                    Variable Expression: ?{}: static inline function
                    ... with parameters
                      _dst: reference to instance of struct A with body 1
                      _src: instance of struct A with body 1
                    ... returning nothing

                  ... to arguments
                    Variable Expression: __multassign_L0: reference to instance of struct A with body 1
                    Variable Expression: __multassign_R0: instance of struct A with body 1

                  Application of
                    Variable Expression: ?{}: static inline function
                    ... with parameters
                      _dst: reference to instance of struct A with body 1
                      _src: instance of struct A with body 1
                    ... returning nothing

                  ... to arguments
                    Variable Expression: __multassign_L1: reference to instance of struct A with body 1
                    Variable Expression: __multassign_R1: instance of struct A with body 1
}}}

"	defect	new	major	cfa-cc	1.0		tuple, copy, constructor	
