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

Viewed 625

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.1:

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?

For the sake of clarity:

  • here the compilation succeeds using clang 3.7.1
  • here the compilation fails using GCC 5.3.0

See this link to the bugzilla for the GCC compiler for further details.
Currently, the bug is still unconfirmed. I'll update the question as soon as possible.

1 Answers
Related