http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55038



             Bug #: 55038

           Summary: c++11: operator +=

    Classification: Unclassified

           Product: gcc

           Version: 4.7.1

            Status: UNCONFIRMED

          Severity: enhancement

          Priority: P3

         Component: c++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: lis...@lisp2d.net





I transfer code to c++(2011) version and hear: the main goal is to advance

using an rvalue.

 But standard say that operators +=,++,-=,-- must have an lvalue from the left

side.

 Who are writes the standard? 

 And why I must to write cover class?

 And I want to hear an advice.



code:



#include  <iostream>

#include  <complex>



namespace test{



class Int{

public:

  signed  int i;

  Int()noexcept:i(){}

  constexpr Int(Int const & x)noexcept:i{x.i}{}

  constexpr explicit  Int(signed  int const & x)noexcept:i{x}{}

  Int & operator  =(Int const & x)noexcept{i  = (x.i);return  * this;}

  void  Swap(Int  &  x){std::swap(i,x.i);}

  Int operator  +(Int  const & x){return  Int{i + (x.i)};}

  Int & operator  +=(Int  const & x){i  +=  (x.i);return  * this;}

};



int main(int,char * *){

  Int x{1};

  Int y{2};

  Int z{3};

  std::cout <<  "(" <<  x.i <<  "+" <<  y.i <<  ")+=" <<  z.i <<  " = " <<  ((x

+ y) +=  z).i <<  std::endl;

  std::complex<int>  cx{1};

  std::complex<int>  cy{2};

  std::complex<int>  cz{3};

  std::cout <<  "(" <<  cx <<  "+" <<  cy <<  ")+=" <<  cz <<  " = " <<  ((cx +

cy) +=  cz) <<  std::endl;

  int ix{1};

  int iy{2};

  int iz{3};

  //std::cout <<  "(" <<  ix <<  "+" <<  iy <<  ")+=" <<  iz <<  " = " <<  ((ix

+ iy) +=  iz) <<  std::endl;

  }



} // namespace test



int main(int  n,char * *  a){

  return  test::main(n,a);}

Reply via email to