This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/77274] New: GCC uses copy constructor in member initializer list instead of simple initialization


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77274

            Bug ID: 77274
           Summary: GCC uses copy constructor in member initializer list
                    instead of simple initialization
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yanp.bugz at gmail dot com
  Target Milestone: ---

Code example:

struct C{
        static int count;
        C(int, int) {count++;}
};

#define BUG

struct C1{
        static int count;
        explicit C1() {count++;}
        C1(const C1& ) 
        #ifdef BUG
        = delete;
        #else
        {
                cout<<"copy ctor\n";
                count++;
        }
        C1(C1&& ) {
                cout<<"move ctor\n";
                count++;
        }
        #endif
};

struct D{
        D() : c(C(2,3)), cc(3,4) c1(C1()) {}
        C c, cc;
        C1 c1;
};

Compiler gives you error:
new.cxx: In constructor ‘D::D()’:
new.cxx:79:35: error: use of deleted function ‘C1::C1(const C1&)’
  D() : c(C(2,3)), cc(3,4), c1(C1()) {}
                                   ^
new.cxx:63:2: note: declared here
  C1(const C1& ) 
  ^

However if you undef BUG you will notice that none of copy/move ctors were
called

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]