This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/31156] New: creates reference to copy constructor on use of temporary object
- From: "charles at vmware dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Mar 2007 21:47:04 -0000
- Subject: [Bug c++/31156] New: creates reference to copy constructor on use of temporary object
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following code fails to compile:
>>>> begin
#include <iostream>
class Foo
{
Foo(const Foo&); // private
public:
Foo(int x) { }
};
std::ostream &operator <<(std::ostream &out, const Foo &)
{
return out;
}
int main()
{
std::cout << Foo(5);
}
// test.cpp:5: error: 'Foo::Foo(const Foo&)' is private
// test.cpp:17: error: within this context
<<<< end
It does compile with EDG's C++ frontend.
reproduced on gcc version 4.1.2 (Gentoo 4.1.2)
reproduced on gcc version 4.1.1 (Gentoo 4.1.1-r3)
_not_ reproduced on gcc version 3.3.6 (Debian 1:3.3.6-15)
The following also fails on (Debian 4.1.1-21):
>>>> begin
class Foo
{
Foo(const Foo&); // private
public:
Foo(int x) { }
};
void foo(const Foo &) { }
int main()
{
foo(Foo(5));
}
// test.cpp:3: error: 'Foo::Foo(const Foo&)' is private
// test.cpp:12: error: within this context
<<<< end
Likewise, the following test, demonstrating that it's based on temporaries,
successfully compiles:
>>>> begin
class Foo
{
Foo(const Foo&); // private
public:
Foo(int x) { }
};
void foo(const Foo &) { }
int main()
{
Foo f(5);
foo(f);
}
<<<< end
--
Summary: creates reference to copy constructor on use of
temporary object
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: charles at vmware dot com
GCC build triplet: gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-
21)
GCC host triplet: gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-
21)
GCC target triplet: gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-
21)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31156