[Bug c++/27295] New: Compiler expects public access of copy constructor eventhough the cp ctr never get's invoked.
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 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
[Bug c++/27295] Compiler expects public access of copy constructor eventhough the cp ctr never get's invoked.
--- Comment #1 from ram dot misc at gmail dot com 2006-04-24 23:24 --- Correction: Bug/problem context is GCC 3.4.5 (not 2.4.5) Thank you. (In reply to comment #0) > 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 > 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. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27295