This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/77274] New: GCC uses copy constructor in member initializer list instead of simple initialization
- From: "yanp.bugz at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 16 Aug 2016 20:49:45 +0000
- Subject: [Bug c++/77274] New: GCC uses copy constructor in member initializer list instead of simple initialization
- Authentication-results: sourceware.org; auth=none
- Auto-submitted: auto-generated
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