Bug 18448 - g++ attempts to use copy constructor instead of operator = on instantiated object
Summary: g++ attempts to use copy constructor instead of operator = on instantiated ob...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-12 10:42 UTC by Vladimir
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
testcase (119 bytes, application/octet-stream)
2004-11-12 10:43 UTC, Vladimir
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir 2004-11-12 10:42:43 UTC
gcc-3.4.2/4.0.0
Linux **** 2.6.9 #17 Fri Nov 12 15:59:30 NOVT 2004 i686 athlon i386 GNU/Linux
Fedora Core 3

gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix --disa
Thread model: posix
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)

g++ test.cpp

[megath@hell temp]$ g++ test.cpp
test.cpp: In function `int main()':
test.cpp:10: error: `A::A(const A&)' is private
test.cpp:16: error: within this context

test.cpp:

class A {
public:
A() {}
const A& operator=(const A& a) {
    return *this;
}

private:
A(const A& a) {}
};

A a;
int main() {
    A *pa = &a;
    *pa = A();
}
Comment 1 Vladimir 2004-11-12 10:43:54 UTC
Created attachment 7527 [details]
testcase
Comment 2 Andrew Pinski 2004-11-12 12:39:34 UTC
Invalid, did you read the release notes?
Comment 3 Vladimir 2004-11-12 13:10:37 UTC
about 
<i>Copy constructor access check while initializing a reference.</i> 
? yes. sorry.
*p = A() constructs copy of object now? what for ? 
doesnt it degrades perfomance?
Comment 4 Andrew Pinski 2004-11-12 13:41:07 UTC
(In reply to comment #3)
> about 
> <i>Copy constructor access check while initializing a reference.</i> 
> ? yes. sorry.
> *p = A() constructs copy of object now? what for ? 
No we don't contruct a copy of the object, did you really read it.  I just says it has to be accessable, it 
will not be used.
> doesnt it degrades perfomance?
Only slightly compile time and that is it.
Comment 5 Vladimir 2004-11-12 13:48:02 UTC
> I just says it has to be accessable
so, if gcc dont use copy ctor - what for it complains ?! 
and why is it error btw ?
Comment 6 Andrew Pinski 2004-11-12 13:54:38 UTC
(In reply to comment #5)
> > I just says it has to be accessable
> so, if gcc dont use copy ctor - what for it complains ?! 
Because this is the requirement of the C++ standard.

> and why is it error btw ?
because we could use the ctor if we wantted to in this case but we don't so the requirement of the C++ 
standard says it has to be accessable.
Comment 7 Vladimir 2004-11-12 13:57:42 UTC
thank you.