C++11 Clause 12.7 paragraph 3

Discussion in 'C++' started by jabelloc@gmail.com, May 2, 2013.

  1. Guest

    1. What are the specific problems that are being avoided with the restrictions imposed by this clause `12.7p3` (see the first part of paragraph below)?

    2. In the example shown in `12.7p3` (see below) why `X(this)` is considered defined? Is it because `X` is not in the path `E C D B A` ?

    struct A { };
    struct B : virtual A { };
    struct C : B { };
    struct D : virtual A { D(A*); };
    struct X { X(A*); };
    struct E : C, D, X {
    E() : D(this), // undefined: upcast from E* to A*
    // might use path E* - D* - A*
    // but D is not constructed
    // D((C*)this), // defined:
    // E* - C* defined because E() has started
    // and C* - A* defined because
    // C fully constructed
    X(this) { // defined: upon construction of X,
    // C/B/D/A sublattice is fully constructed
    }
    };

    3. Please find below the start of paragraph `12.7p3`:

    > To explicitly or implicitly convert a pointer (a glvalue) referring to
    > an object of class X to a pointer (reference) to a direct or indirect
    > base class B of X, the construction of X and the construction of all
    > of its direct or indirect bases that directly or indirectly derive
    > from B shall have started and the destruction of these classes shall
    > not have completed, otherwise the conversion results in undefined
    > behavior.



    Is it correct to say that the set of all direct and indirect bases of `X`, mentioned above don't include `B`, and because of this the code below is well defined, notwithstanding the fact that `Base` is a direct base of `Derived` and has yet not started?

    struct Base{ Base(Base*); };

    struct Derived : Base {
    Derived() : Base(this) {};
    };
     
    , May 2, 2013
    #1
    1. Advertising

  2. Bo Persson Guest

    skrev 2013-05-02 16:29:
    > 1. What are the specific problems that are being avoided with the restrictions imposed by this clause `12.7p3` (see the first part of paragraph below)?
    >
    > 2. In the example shown in `12.7p3` (see below) why `X(this)` is considered defined? Is it because `X` is not in the path `E C D B A` ?
    >
    > struct A { };
    > struct B : virtual A { };
    > struct C : B { };
    > struct D : virtual A { D(A*); };
    > struct X { X(A*); };
    > struct E : C, D, X {
    > E() : D(this), // undefined: upcast from E* to A*
    > // might use path E* - D* - A*
    > // but D is not constructed
    > // D((C*)this), // defined:
    > // E* - C* defined because E() has started
    > // and C* - A* defined because
    > // C fully constructed
    > X(this) { // defined: upon construction of X,
    > // C/B/D/A sublattice is fully constructed
    > }
    > };
    >
    > 3. Please find below the start of paragraph `12.7p3`:
    >
    >> To explicitly or implicitly convert a pointer (a glvalue) referring to
    >> an object of class X to a pointer (reference) to a direct or indirect
    >> base class B of X, the construction of X and the construction of all
    >> of its direct or indirect bases that directly or indirectly derive
    >> from B shall have started and the destruction of these classes shall
    >> not have completed, otherwise the conversion results in undefined
    >> behavior.

    >
    >
    > Is it correct to say that the set of all direct and indirect bases of `X`, mentioned above don't include `B`, and because of this the code below is well defined, notwithstanding the fact that `Base` is a direct base of `Derived` and has yet not started?
    >
    > struct Base{ Base(Base*); };
    >
    > struct Derived : Base {
    > Derived() : Base(this) {};
    > };
    >


    Yes.

    The example is mostly about virtual inheritance and the problem is that
    both C and D are derived from A, but there will still only be one A in a
    complete E object.

    Until both C and D are fully constructed, the compiler isn't required to
    know how to get a pointer to the A base class of E (and even then it's
    pretty complicated).

    You don't have ANY of those problems.


    Bo Persson
     
    Bo Persson, May 2, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anno Siegel

    Re: read a paragraph via scrit?

    Anno Siegel, Apr 1, 2004, in forum: Perl
    Replies:
    0
    Views:
    453
    Anno Siegel
    Apr 1, 2004
  2. Jim Heavey

    Paragraph Name

    Jim Heavey, Dec 3, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    466
    Jim Heavey
    Dec 4, 2003
  3. MW de Jager

    HTML Paragraph question

    MW de Jager, Jul 6, 2005, in forum: ASP .Net
    Replies:
    9
    Views:
    468
    John Timney \(ASP.NET MVP\)
    Jul 6, 2005
  4. ad
    Replies:
    4
    Views:
    409
    UT-BadBoy
    Feb 23, 2006
  5. dorayme
    Replies:
    112
    Views:
    2,742
    dorayme
    Mar 30, 2009
Loading...

Share This Page