The following code doesn't compile with gcc, but it compiles with clang.
struct Base {
void base() {}
};
template< typename T >
struct Foo : Base {
struct Bar : Base {
};
struct Baz : Bar {
void f() {
base();
}
};
};
int main() {
Foo<int>::Baz{}.f();
}
gcc spits the following error:
13:11: error: cannot call member function 'void Base::base()' without object
13 | base();
| ~~~~^~
Interestingly, if I change it to this->base();
or Base::base();
, then it compiles.
Why can't gcc find the Base
class object? Baz
is clearly a subclass of Base
.