2

In following example struct Derived<T> inherits from Base<T> and defines an alias to its parent with the name Base:

template <class T>
struct Base {
    Base(int) {}
};

template <class T>
struct Derived : Base<T> {
    using Base = Base<T>;
    Derived() : Base(1) {}
};

int main() {
    Derived<char> x;
}

Clang permits this code, but GCC prints the error:

error: declaration of 'using Base = struct Base<T>' changes meaning of 'Base' [-fpermissive]

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

Which compiler is right here?

Fedor
  • 17,146
  • 13
  • 40
  • 131
  • Just a note, apart from actually specifying the base, `Base` name is already injected into `Derived` scope, `Derived::Base y{1};` will work even without the alias (for public inheritance ofc). – Quimby Nov 20 '21 at 19:16

0 Answers0