Re: copy constructors and printf

From: Dave Moore (dtmoore_at_rijnh.nl)
Date: 04/29/04


Date: 29 Apr 2004 09:00:28 -0700

Rob Williscroft <rtw@freenet.co.uk> wrote in message news:<Xns94D9AEB29866BukcoREMOVEfreenetrtw@130.133.1.4>...
> Dave Moore wrote in news:306d400f.0404280144.22bd8d7@posting.google.com
> in comp.lang.c++:
>
> > "John Harrison" <john_andronicus@hotmail.com> wrote in message
> > news:<c6m7pc$dir2s$1@ID-196037.news.uni-berlin.de>...
> >> "Sam Wilson [Bentley]" <sam.wilson@bentley.com> wrote in message
> >> news:408E8107.724EB6EE@bentley.com...
> >> > If you pass a C++ object by value as an argument to a function
> >> > which has
> >> >
> >> > a variable-length argument list (...), the MSVC7 C++ compiler does
> >> > not call the object's copy constructor and will not complain if the
> >> > copy constructor is private.
> >> >
> >> > 1) Is this part of the C++ language definition? What is the
> >> > thinking behind it?
> >>
> >> Kind of, the C++ standard just says that such behaviour is undefined.
> >>
> >
> > Please cite chapter and verse from the Standard when making such
> > assertions. In this case I think you are incorrect ... the rules for
> > arguments without parameters (5.2.2/7) don't say anything explicit
> > about the copy constructor. Basically they imply that an rvalue
> > argument that has class type will be used "as-is" ... which I assume
>
> This makes no sense at all, how can an rvalue (or anything else for that
> matter) be passed without copying ?

Well, I guess I see your point, but then how is a pass-by-value
argument of POD-type handled in a variadic function call? In Jerry
Coffin's response to my post in this thread, he said that a ctor
should be called "to initialize the parameter", but as I understand it
from 5.2.2/7 (which IMO is kind of vague here), there *is* no
parameter in a variadic function call (for arguments matching the ...
anyway), only an argument. So is my statement below about deferring
the copy constructor until the va_arg call correct?

> > to mean that the call to the copy constructor is deferred until the
> > call to va_arg in the function body.

OTOH, maybe there is some effect of the statement " .. lvalue to
rvalue conversion ... will be performed" in 5.2.2/7 that I am not
seeing? I would say that a POD-type object passed by value is an
rvalue, but I remember seeing somewhere in the Standard (I can't find
it anymore) that objects of class type are always passed to functions
as lvalues.

Please help me out of my confusion.

TIA, Dave Moore

P.S. I expect there is more info on this in the C-Standard, but I
don't have a copy of that.



Relevant Pages

  • Re: Casting double to int produces inconsistent results from VS 2003 to VS 2008
    ... Some things in the standard are ... 4.8p1 An rvalue of floating point type can be converted to an rvalue of ... another floating point type. ... the result of the conversion is ...
    (microsoft.public.vc.language)
  • Re: Whats going on here?!
    ... > the rvalue to be created. ... can anyone tell me why the standard allows a copy of the rvalue to be ... Foo const& f = makeFoo(); //temporary lasts as long as f. ...
    (microsoft.public.vc.language)
  • Re: _Complex_I
    ... What is sometimes called "rvalue" is in this International ... Standard described as the "value of an expression". ... declared as designating an object ... I don't see an explicit statement that the result is the value of the ...
    (comp.std.c)
  • Re: copy constructors and printf
    ... Basically they imply that an rvalue ... >> to mean that the call to the copy constructor is deferred until the ... > I was assuming the OP was talking about a non-POD type. ... However I am utter newbie to TMP, ...
    (comp.lang.cpp)
  • Re: returning lvalue in C vs C++
    ... basis that fis an rvalue, and a method call on an ... rvalue is OK, but an rvalue on the lhs of an assignment is not. ... But I thought that the expression rvalue.x makes x an lvalue, because The Standard didn't say that rvalue.x must be an rvalue. ... However, I have CHANGED MY STANCE on when assignment is allowed: I now think the standard is too unclear for a straight answer such as the one I gave, which, as I see it know, may even be considered /incorrect/. ...
    (comp.programming)