https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85060
Bug ID: 85060 Summary: Object cannot call its inherited member function "without object" Product: gcc Version: 7.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dingyuc at 126 dot com Target Milestone: --- Created attachment 43746 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43746&action=edit The source code "hierarchy.cc" and a preprocessed file "hierarchy.ii" The attached source code can be compiled and executed by older versions of g++ but not by g++ 7.0.0 - 7.3.1. I managed to simplify the case into three level of classes where child and grandchild classes are templates. The code has been tested on Archlinux, OS_X and some online compilers, all confirming it's a gcc7 problem. Simply the command $ g++ hierarchy.cc will yield hierarchy.cc: In member function ‘void CC<T>::bar()’: hierarchy.cc:20:32: error: cannot call member function ‘int CA::foo()’ without object const SPECIFIER m = CA::foo(); // Won't pass!! Here is the complete source code for people bothered to untar: $ cat hierarchy.cc #include <iostream> #ifndef SPECIFIER #define SPECIFIER int // fail with g++7 // #define SPECIFIER auto // fail with g++7, or invalid without c++11 // #define SPECIFIER T // pass with g++7 when int->T is possible #endif class CA { public: int foo() { return 42; } }; template <class T> class CB : public CA { }; template <class T> class CC : public CB<T> { public: void bar() { const SPECIFIER m = CA::foo(); // Won't pass!! // const SPECIFIER m = this->CA::foo(); // This will work. std::cout << "THE ULTIMATE ANSWER: " << m << std::endl; } }; int main(void) { CC<double> c; c.bar(); return 0; }