tilin
tilin

Reputation: 332

GCC compilation error when inheriting constructors

This code is compiled by gcc with an error

template<typename>
struct B {
};

template<typename... Types>
struct A : public B<Types>... {
    using B<Types>::B...;
    using B<Types>::operator=...;
}

compiler output

<source>:8:8: error: expected nested-name-specifier before 'B'

    8 |  using B<Types>::operator=...;

      |   

 ^

But this code compiles without errors

template<typename>
struct B {
};

template<typename... Types>
struct A : public B<Types>... {
    using B<Types>::operator=...;
    using B<Types>::B...;
};

I can 't understand why this is happening.


Update

for gcc, constructor inheritance also breaks the code

template<typename T>
struct B {
    void foo() {}
};

template<typename... Types>
struct A : public B<Types>... {
    using B<Types>::B...;

    void bar() {
        (B<Types>::foo() , ...);
    }
};

Upvotes: 6

Views: 87

Answers (1)

Fedor
Fedor

Reputation: 21307

It was a GCC bug, that was fixed finally in GCC 11.

Demo: https://gcc.godbolt.org/z/arxjPjTa5

Another demo: https://gcc.godbolt.org/z/KhjGn945G

Upvotes: 1

Related Questions