Re: Compiler chooses conv ctor - why?



Cezary H. Noweta wrote:
Hello,

Alex Blekhman wrote:
struct Y {};

class X
{
public:
X() {}
X(Y) {}
private:
X(const X&);
};

int main()
{
Y y;
X x1 = y; // ill-formed, inaccessible cctor
X x2(y); // OK, direct initialization

return 0;
}

According to the standard `x1' instance cannot be constructed due to
inaccessible copy constructor (which may be eliminated during
construction of an object by the compiler, but the copy semantics
must be preserved anyway).

But this elimination is an element of the semantics (8.5[14]). Such
elimination involves an elimination of checking cctor access, doesn't
it?

Huh? Elimination of the copy is allowed, but not required. Even if it
is forgone (the compiler decides to optimize it away), the copy-ctor has
to be available _as_if_ it were used (12.8/15).

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: Iteration in lisp
    ... funcall for indicating your code ... compiler can't guarantee the elimination. ... Implementations that don't know about it would error out given "funtail" ...
    (comp.lang.lisp)
  • Re: MACROLET and lexical environment
    ... > Well, yes, but the compiler doesn't get a chance to do this if the ... > macro throws a fit at macro expansion time. ... But if dead-code elimination happens in a separate pass after ...
    (comp.lang.lisp)
  • Fortran array optimizations
    ... i know that compilers can perform "common subexpression elimination", ... to avoid repeated evaluation of complex expressions, ... Will the compiler evaluate 1/y to a temporary array in each cycle, ...
    (comp.lang.fortran)
  • Re: copy ctor question
    ... > for each member and base class. ... The compiler generated copy constructor isn't ... > do proper copy semantics themselves. ... Secondly you can't put a breakpoint on a compiler generated ...
    (comp.lang.cpp)
  • Re: Compiler chooses conv ctor - why?
    ... int main ... X x2; // OK, direct initialization ... inaccessible copy constructor. ... elimination involves an elimination of checking cctor access, ...
    (microsoft.public.vc.language)

Loading