[Bug c++/27295] New: Compiler expects public access of copy constructor eventhough the cp ctr never get's invoked.
ram dot misc at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Apr 24 23:20:00 GMT 2006
The foll. code works with GCC 2.95.2; however, it fails compile on GCC 2.4.5.
Whenever an anonymous object is passed as function argument, the compiler is
expecting "public access" to the copy constructor of the passed type - even
though the cp ctr never get's invoked.
====================================
compilation error: [g++ 3.4.5]
private_cp_ctr.cc: In function `int main()':
private_cp_ctr.cc:42: error: `Foo::Foo(const Foo&)' is private
private_cp_ctr.cc:60: error: within this context
====================================
code:
#include <cstdio>
class Foo
{
public:
Foo()
{
printf( "ctr called.\n" );
}
private:
Foo(const Foo&) // problem location
{
printf( "cp ctr called.\n" );
}
};
void evaluate(const Foo& ref)
{
printf( "evaluate called.\n" );
}
int main()
{
Foo f;
evaluate(f); // ok: no compile error
// problem context. compiler checks for copy ctr public visibility
// eventhough the copy ctr never get's invoked in the context.
evaluate(Foo());
return 0;
}
==================================
Thankyou.
--
Summary: Compiler expects public access of copy constructor
eventhough the cp ctr never get's invoked.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ram dot misc at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27295
More information about the Gcc-bugs
mailing list