Bug 164141
Summary: | g++ requires public copy constructor (ctor) | ||||||
---|---|---|---|---|---|---|---|
Product: | [Fedora] Fedora | Reporter: | Graham Hudspith <graham.hudspith> | ||||
Component: | gcc | Assignee: | Jakub Jelinek <jakub> | ||||
Status: | CLOSED NOTABUG | QA Contact: | |||||
Severity: | medium | Docs Contact: | |||||
Priority: | medium | ||||||
Version: | 4 | CC: | jason | ||||
Target Milestone: | --- | ||||||
Target Release: | --- | ||||||
Hardware: | i386 | ||||||
OS: | Linux | ||||||
Whiteboard: | |||||||
Fixed In Version: | Doc Type: | Bug Fix | |||||
Doc Text: | Story Points: | --- | |||||
Clone Of: | Environment: | ||||||
Last Closed: | 2005-07-26 09:55:57 UTC | Type: | --- | ||||
Regression: | --- | Mount Type: | --- | ||||
Documentation: | --- | CRM: | |||||
Verified Versions: | Category: | --- | |||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
Cloudforms Team: | --- | Target Upstream Version: | |||||
Embargoed: | |||||||
Attachments: |
|
Description
Graham Hudspith
2005-07-25 11:13:03 UTC
Created attachment 117117 [details]
Sample test program.
Sigh! In my "Steps to Reproduce", above, please swap steps 1 and 3 ... 1. g++ -DNEED_COPY_CTOR -o privateCtor -O0 -g privateCtor.cpp 2. compile succeeds 3. g++ -o privateCtor -O0 -g privateCtor.cpp 4. compile fails Sigh! Better kill off this bug report! Just found this in the GCC v3.4 release notes: http://gcc.gnu.org/gcc-3.4/changes.html and the "non BUGS" webpage: http://gcc.gnu.org/bugs.html#cxx_rvalbind I'll send this off to the third-party add-on people too. Sorry for any wasted time you've spent on this ... ------------ snip snip ------------ Copy constructor access check while initializing a reference. Consider this code: class A { public: A(); private: A(const A&); // private copy ctor }; A makeA(void); void foo(const A&); void bar(void) { foo(A()); // error, copy ctor is not accessible foo(makeA()); // error, copy ctor is not accessible A a1; foo(a1); // OK, a1 is a lvalue } Starting with GCC 3.4.0, binding an rvalue to a const reference requires an accessible copy constructor. This might be surprising at first sight, especially since most popular compilers do not correctly implement this rule. The C++ Standard says that a temporary object should be created in this context and its contents filled with a copy of the object we are trying to bind to the reference; it also says that the temporary copy can be elided, but the semantic constraints (eg. accessibility) of the copy constructor still have to be checked. For further information, you can consult the following paragraphs of the C++ standard: [dcl.init.ref]/5, bullet 2, sub-bullet 1, and [class.temporary]/2. Spooky how close my sample test program was to the GNU example :-) |