#define FAILS /* gcc (GCC) 3.3 20030226 (prerelease) (SuSE Linux) tzst2.cpp: In function `void foo(const SA*)': tzst2.cpp:29: error: `CA::CA(const CA&)' is private tzst2.cpp:34: error: within this context tzst2.cpp:34: error: initializing temporary from result of `CA::CA(const SA&) */ // Data layout only struct SA { }; class CA :protected SA { public: CA() { }; CA(const SA& a) { }; #ifdef FAILS private: CA(const CA& a); #endif }; void foo(const SA * pa) { const CA& ra=*pa; }
The error is right you have to an accessorable copy constructor when initing a variable.
That's not a variable, it's a reference. GCC should not call any constructor when binding the variable to that reference.
Uhm, ok, it must call a copy constructor, but the first one.
Ok. Given: ------------------------------------ struct A {}; struct B : protected A { B() {}; B(const A& ) {}; private: B(const B& ) {}; }; void foo(const A* ap) { const B& br = *ap; } ------------------------------------ The code should compile, because it should call B(const A&) to construct the temporary which is then bound to the const reference. Instead, GCC seems to call B(const B&), which is private. I can't test on 3.0/3.1, but it's surely a regression since 3.0.4, and can be made a wrong-code one if we make the constructor public. I keep it as rejects-valid as it's easier to debug.
Failing since at least 2000-12-31.
Subject: Bug 13478 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2004-01-16 16:59:30 Modified files: gcc/cp : ChangeLog call.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/init: ref10.C Log message: PR c++/13478 * call.c (convert_like_real): Do not perform an additional direct-initialization when binding to a reference. PR c++/13478 * g++.dg/init/ref10.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3887&r2=1.3888 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.449&r2=1.450 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3384&r2=1.3385 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/ref10.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 13478 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2004-01-16 17:54:25 Modified files: gcc/cp : ChangeLog call.c Log message: PR c++/13478 * call.c (initialize_reference): Pass -1 for inner parameter to convert_like_real. PR c++/13478 * g++.dg/init/ref10.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3888&r2=1.3889 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.450&r2=1.451
Fixed in GCC 3.4.
Subject: Bug 13478 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: gdr@gcc.gnu.org 2004-01-21 07:30:07 Modified files: gcc/cp : ChangeLog call.c Added files: gcc/testsuite/g++.dg/init: ref10.C Log message: Backport from mainline 2004-01-16 Mark Mitchell <mark@codesourcery.com> PR c++/13478 * call.c (initialize_reference): Pass -1 for inner parameter to convert_like_real. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.240&r2=1.3076.2.241 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.341.2.35&r2=1.341.2.36 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/ref10.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.6.1
Fixed with a backport from mainline.