vendredi 4 mars 2016

noexcept, inheriting constructors and the invalid use of an incomplete type that is actually complete

I'm not sure if it's a bug of the GCC compiler or the intended behavior of noexcept.
Consider the following example:

struct B {
    B(int) noexcept { }
    virtual void f() = 0;
};

struct D: public B {
    using B::B;
    D() noexcept(noexcept(D{42})): B{42} { }
    void f() override { }
};

int main() {
    B *b = new D{};
}

If the noexcept is removed, it compiles.
Anyway, as it is in the example, I got this error from GCC v5.3.0:

test.cpp:8:31: error: invalid use of incomplete type ‘struct D’
     D() noexcept(noexcept(D{42})): B{42} { }
                               ^

As far as I know, struct D is not an incomplete type, but inheriting constructors are involved in the statement and it looks like the compiler is actually considering the completeness of the base struct B more than of D.

Is that the intended behavior or is it legal code?

Aucun commentaire:

Enregistrer un commentaire