public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Problem with private copy constructor
@ 2006-06-26  9:57 Mathias Froehlich
  2006-06-26 10:11 ` corey taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Mathias Froehlich @ 2006-06-26  9:57 UTC (permalink / raw)
  To: gcc-help


Hi,

I have a problem with that following code together with gcc-4.1.1.

#include <iostream>

class base {
public:
   base()
   { std::cout << __PRETTY_FUNCTION__ << " " << this << std::endl; }
private:
   base(const base&);
};

class derived : public base {
public:
   derived()
   { std::cout << __PRETTY_FUNCTION__ << " " << this << std::endl; }
};

void fuu(const base& b)
{
}

int main()
{
   fuu(derived());
   return 17;
}

gcc bails out with the following error message:

gcctest2.cpp: In copy constructor 'derived::derived(const derived&)':
gcctest2.cpp:8: error: 'base::base(const base&)' is private
gcctest2.cpp:11: error: within this context
gcctest2.cpp: In function 'int main()':
gcctest2.cpp:23: note: synthesized method 'derived::derived(const derived&)' 
first required here 

From my understanding of c++, I would not expect that this copy constructor is 
called in this case. In fact, gcc-3.3.4 and various other UNIX c++ compilers 
do not need that copy constructor either.

Do I need to dig out my copy of the C++ standard or is it something to file a 
bugreport?

    Greetings

          Mathias

-- 
Dr. Mathias Fröhlich, science + computing ag, Software Solutions
Hagellocher Weg 71-75, D-72070 Tuebingen, Germany
Phone: +49 7071 9457-268, Fax: +49 7071 9457-511

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Problem with private copy constructor
  2006-06-26  9:57 Problem with private copy constructor Mathias Froehlich
@ 2006-06-26 10:11 ` corey taylor
  2006-06-26 11:15   ` Mathias Froehlich
  0 siblings, 1 reply; 3+ messages in thread
From: corey taylor @ 2006-06-26 10:11 UTC (permalink / raw)
  To: Mathias Froehlich; +Cc: gcc-help

This has changed sinced 3.4 and is now correct based on the standard:

http://gcc.gnu.org/bugs.html#cxx_rvalbind has good information on this.

corey

On 6/26/06, Mathias Froehlich <M.Froehlich@science-computing.de> wrote:
>
> Hi,
>
> I have a problem with that following code together with gcc-4.1.1.
>
> #include <iostream>
>
> class base {
> public:
>   base()
>   { std::cout << __PRETTY_FUNCTION__ << " " << this << std::endl; }
> private:
>   base(const base&);
> };
>
> class derived : public base {
> public:
>   derived()
>   { std::cout << __PRETTY_FUNCTION__ << " " << this << std::endl; }
> };
>
> void fuu(const base& b)
> {
> }
>
> int main()
> {
>   fuu(derived());
>   return 17;
> }
>
> gcc bails out with the following error message:
>
> gcctest2.cpp: In copy constructor 'derived::derived(const derived&)':
> gcctest2.cpp:8: error: 'base::base(const base&)' is private
> gcctest2.cpp:11: error: within this context
> gcctest2.cpp: In function 'int main()':
> gcctest2.cpp:23: note: synthesized method 'derived::derived(const derived&)'
> first required here
>
> From my understanding of c++, I would not expect that this copy constructor is
> called in this case. In fact, gcc-3.3.4 and various other UNIX c++ compilers
> do not need that copy constructor either.
>
> Do I need to dig out my copy of the C++ standard or is it something to file a
> bugreport?
>
>    Greetings
>
>          Mathias
>
> --
> Dr. Mathias Fröhlich, science + computing ag, Software Solutions
> Hagellocher Weg 71-75, D-72070 Tuebingen, Germany
> Phone: +49 7071 9457-268, Fax: +49 7071 9457-511
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Problem with private copy constructor
  2006-06-26 10:11 ` corey taylor
@ 2006-06-26 11:15   ` Mathias Froehlich
  0 siblings, 0 replies; 3+ messages in thread
From: Mathias Froehlich @ 2006-06-26 11:15 UTC (permalink / raw)
  To: corey taylor; +Cc: gcc-help

On Monday 26 June 2006 12:11, corey taylor wrote:
> This has changed sinced 3.4 and is now correct based on the standard:
>
> http://gcc.gnu.org/bugs.html#cxx_rvalbind has good information on this.
Ok, thanks!

    Greetings

              Mathias
   
-- 
Dr. Mathias Fröhlich, science + computing ag, Software Solutions
Hagellocher Weg 71-75, D-72070 Tuebingen, Germany
Phone: +49 7071 9457-268, Fax: +49 7071 9457-511

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-06-26 11:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-26  9:57 Problem with private copy constructor Mathias Froehlich
2006-06-26 10:11 ` corey taylor
2006-06-26 11:15   ` Mathias Froehlich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).