Re: Inadequate error message C2228

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Vladimir Grigoriev wrote:
"Cezary H. Noweta" <chncc@xxxxxxxxxxxxxxx> wrote in message
news:ugTNvN$nIHA.3376@xxxxxxxxxxxxxxxxxxxxxxx

Yes, but (B(a)) still can be (and really it is) optimized to B(a),
thus copy ctor will be omitted. In ((void)0, B(A)) copy ctor could
be omitted too (there is no sequence point after a whole
expression), but hopefully compilers are not happy to do this.
Certainly, the safest way to call the copy ctor is to introduce a
temporary object manually.

It is interesting to note that different compilers behave differently.
Visual C++ 2003 EE omits copy ctor for the statement
B b( ( B( a ) ) );
while BCB 5.0 calls copy ctor as it is specified explicitly.

I for one do not share your view that this is "interesting". So what
if the compilers have different ways of implementing this. All within
allowed behaviour, according to the Standard... What might be (or is)
interesting is how many programmers do not know that making a copy
is allowed to be omitted and try to rely on the copy's being made...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


.



Relevant Pages

  • Re: Should this code compile?
    ... > All this stuff about copy initilialization, ... Most compilers will NOT call the ... > copy ctor anyway in order to compile the above piece of code, ...
    (comp.lang.cpp)
  • Re: Inadequate error message C2228
    ... B) copy ctor could be omitted ... too (there is no sequence point after a whole expression), ... It is interesting to note that different compilers behave differently. ... Vladimir Grigoriev ...
    (microsoft.public.vc.language)
  • Re: Should this code compile?
    ... a resource that is too expensive to copy (e.g. a huge amount of ... memory). ... Most compilers will NOT call the ... copy ctor anyway in order to compile the above piece of code, ...
    (comp.lang.cpp)
  • Re: Repeated instantiation of a variable / performance?
    ... > repeated instanciation of k in sequence A a certain cost compared with the ... The second case has one ctor call, one dtor, and 10 ...
    (comp.lang.cpp)
  • Re: The C++ standards rule for selecting a constructor
    ... Vladimir Grigoriev wrote: ... This is not so good programming practice to implement changing of values of object in the copy ctor. ... but if you want to play with some strange behaviors of copy ctors then you have what you want - do not be surprised;) If your initials are not B.S. then it is better if you will avoid all strangisms in your code;) ...
    (microsoft.public.vc.language)