Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
should this compile?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
usenet_...@lehrerfamily.com  
View profile  
 More options Mar 24, 6:17 pm
Newsgroups: comp.lang.c++.moderated
From: usenet_...@lehrerfamily.com
Date: Tue, 24 Mar 2009 16:17:53 CST
Local: Tues, Mar 24 2009 6:17 pm
Subject: should this compile?
The following code fails to compile on my platform.  Testing Comeau
online when they use the same EDG parser we use it fails.  More recent
versions of their compiler successfully compile the code.

struct foo {
  foo();
private:
  foo(const foo &rhs);

};

void func1(const foo &);

void func2() {
  func1( foo() );

}

The question is, does "func1(foo());" require access to foo's copy
constructor?  If it does, it may elide the call, but the copy
constructor must still be accessible.

A co-worker was able to dig the following out of the standard which he
says proves the code should NOT compile.  Do you agree?  My reading of
8.5.3 is that a temporary is created by copying the RValue produced by
foo():

No, it should not compile.
5.2.2
4)
"When a function is called, each parameter (8.3.5) shall be
initialized (8.5, 12.8, 12.1) with its corresponding argument."

8.5.3
... ellided ...
3)
"A reference to type “cv1 T1” is initialized by an expression of type
“cv2 T2” as follows:"
... elidded ...
"— If the initializer expression is an rvalue, with T2 a class type,
and “cv1 T1” is reference-compatible
with “cv2 T2,” the reference is bound in one of the following ways
(the choice is implementation-defined):"

-- The reference is bound to the object represented by the rvalue (see
3.10) or to a sub-object within that object.
— A temporary of type “cv1 T2” [sic] is created, and a constructor is
called to copy the entire rvalue object into the temporary. The
reference is bound to the temporary or to a sub-object within the
temporary.93)
The constructor that would be used to make the copy shall be callable
whether or not the copy is actually done."

thanks for your help.

-Joshua

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
litb  
View profile  
(1 user)  More options Mar 25, 5:25 am
Newsgroups: comp.lang.c++.moderated
From: litb <Schaub-Johan...@web.de>
Date: Wed, 25 Mar 2009 03:25:25 CST
Local: Wed, Mar 25 2009 5:25 am
Subject: Re: should this compile?
On 24 Mrz., 23:17, usenet_...@lehrerfamily.com wrote:

I'm quite sure that will compile with C++1x, but it will fail with
current C++03 rules, because of the paragraph you quoted. In C++1x,
the rules say that the created temporary (which is a rvalue) is bound
without a copy to the const reference. Actually, the comeau online
compiler has a switch to enable C++1x extensions. One of those
extensions they implemented precisely is this bind-to-rvalues-without-
requiring-copy-ctor. If you disable that extension, you will see it
being directed by their online compiler too.

Reference: http://www.comeaucomputing.com/iso/cwg_defects.html#391 and
http://www.comeaucomputing.com/439features.html

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google