public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Passing temprary by reference requires copy constructor in 3.4?
@ 2004-11-26 19:38 Peter Cech
  2004-11-26 19:48 ` Andrew Pinski
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Cech @ 2004-11-26 19:38 UTC (permalink / raw)
  To: gcc

Hi,

trying to compile

class EventObject
{
public:
  EventObject() {}

private:
  EventObject(const EventObject&);
};

class AnyEvent : public EventObject
{
  public:
    AnyEvent() {}

  private:
    AnyEvent(const AnyEvent&);
};

void invoke(const EventObject &) {}

void caller1()
{
  AnyEvent event;
  invoke(event);
}

void caller2()
{
  invoke(AnyEvent());
}

leads to following error with both gcc (GCC) 3.4.3  (Gentoo Linux 3.4.3,
ssp-3.4.3-0, pie-8.7.6.6) and gcc (GCC) 4.0.0 20041121 (experimental)

a.cpp: In function `void caller2()':
a.cpp:16: error: `AnyEvent::AnyEvent(const AnyEvent&)' is private
a.cpp:29: error: within this context

Why gcc requires copy constructor in such situation?

Regards,
Peter Cech

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

* Re: Passing temprary by reference requires copy constructor in 3.4?
  2004-11-26 19:38 Passing temprary by reference requires copy constructor in 3.4? Peter Cech
@ 2004-11-26 19:48 ` Andrew Pinski
  2004-11-26 20:10   ` Mikael Kilpeläinen
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Pinski @ 2004-11-26 19:48 UTC (permalink / raw)
  To: Peter Cech; +Cc: gcc


On Nov 26, 2004, at 2:10 PM, Peter Cech wrote:

> Hi,
> a.cpp: In function `void caller2()':
> a.cpp:16: error: `AnyEvent::AnyEvent(const AnyEvent&)' is private
> a.cpp:29: error: within this context
>
> Why gcc requires copy constructor in such situation?

It does not require the copy constructor, just requires it be 
accessible.
I would read the changes page for 3.4 which documents why this changed.
Mainly this is required by the C++ standard.

Thanks,
Andrew Pinski

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

* Re: Passing temprary by reference requires copy constructor in 3.4?
  2004-11-26 19:48 ` Andrew Pinski
@ 2004-11-26 20:10   ` Mikael Kilpeläinen
  2004-11-26 21:36     ` Andrew Pinski
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Kilpeläinen @ 2004-11-26 20:10 UTC (permalink / raw)
  To: gcc

On Friday 26 November 2004 21:16, Andrew Pinski wrote:
>
> It does not require the copy constructor, just requires it be
> accessible.
> I would read the changes page for 3.4 which documents why this changed.
> Mainly this is required by the C++ standard.

Indeed, however seems that std commitee is removing the restriction. Hence I 
would like to see a flag to disable the error (if there is not one already 
and I am just not aware of it). I am refering to the DR 391.


Mikael

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

* Re: Passing temprary by reference requires copy constructor in 3.4?
  2004-11-26 20:10   ` Mikael Kilpeläinen
@ 2004-11-26 21:36     ` Andrew Pinski
  2004-11-26 21:41       ` Mikael Kilpeläinen
  2004-11-27 18:16       ` Paolo Bonzini
  0 siblings, 2 replies; 6+ messages in thread
From: Andrew Pinski @ 2004-11-26 21:36 UTC (permalink / raw)
  To: Mikael Kilpeläinen; +Cc: gcc


On Nov 26, 2004, at 2:55 PM, Mikael Kilpeläinen wrote:

> On Friday 26 November 2004 21:16, Andrew Pinski wrote:
>>
>> It does not require the copy constructor, just requires it be
>> accessible.
>> I would read the changes page for 3.4 which documents why this 
>> changed.
>> Mainly this is required by the C++ standard.
>
> Indeed, however seems that std commitee is removing the restriction. 
> Hence I
> would like to see a flag to disable the error (if there is not one 
> already
> and I am just not aware of it). I am refering to the DR 391.

Why, the DR is still active so GCC is correct as of right now.
If and when the DR goes to defect, we will implement the needed
change.  But currently GCC is following the standard.

Thanks,
Andrew Pinski

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

* Re: Passing temprary by reference requires copy constructor in 3.4?
  2004-11-26 21:36     ` Andrew Pinski
@ 2004-11-26 21:41       ` Mikael Kilpeläinen
  2004-11-27 18:16       ` Paolo Bonzini
  1 sibling, 0 replies; 6+ messages in thread
From: Mikael Kilpeläinen @ 2004-11-26 21:41 UTC (permalink / raw)
  To: gcc

On Friday 26 November 2004 22:03, Andrew Pinski wrote:
> Why, the DR is still active so GCC is correct as of right now.
> If and when the DR goes to defect, we will implement the needed
> change.  But currently GCC is following the standard.

Yes, I was not saying that gcc is wrong. That was not my intention, I just 
wanted to point out that it is likely to happen and the flag could be helpful 
for certain people. Of course I might be wrong. I just saw fine opportunity 
to talk about this :)


Mikael

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

* Re: Passing temprary by reference requires copy constructor in 3.4?
  2004-11-26 21:36     ` Andrew Pinski
  2004-11-26 21:41       ` Mikael Kilpeläinen
@ 2004-11-27 18:16       ` Paolo Bonzini
  1 sibling, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2004-11-27 18:16 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc

>> Indeed, however seems that std commitee is removing the restriction. 
>> Hence I would like to see a flag to disable the error (if there is not one 
>> already and I am just not aware of it). I am refering to the DR 391.
> 
> Why, the DR is still active so GCC is correct as of right now.
> If and when the DR goes to defect, we will implement the needed
> change.  But currently GCC is following the standard.

It could be material for -fpermissive.  But surely not now that mainline 
is stage3.

Paolo

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

end of thread, other threads:[~2004-11-27  8:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-26 19:38 Passing temprary by reference requires copy constructor in 3.4? Peter Cech
2004-11-26 19:48 ` Andrew Pinski
2004-11-26 20:10   ` Mikael Kilpeläinen
2004-11-26 21:36     ` Andrew Pinski
2004-11-26 21:41       ` Mikael Kilpeläinen
2004-11-27 18:16       ` Paolo Bonzini

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).