https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

            Bug ID: 94799
           Summary: [7.2+ Regression] Calling a member template function
                    fails
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ojman101 at protonmail dot com
  Target Milestone: ---

>From gcc version 7.2 and upwards this c++ code, using a member template
function look-up, fails to compile:

template <typename T>
struct A {
    int a() {
        return 42;
    }
};

template <typename T>
struct B {
    int b(A<T> *p) {
        return p->template A<T>::a();
    }
};

int main() {
    A<int> a;
    B<int> b;
    return b.b(&a);
}

On gcc version 9.3.0 (Gentoo 9.3.0 p2), this output is generated:

main.cc: In member function 'int B<T>::b(A<T>*)':
main.cc:11:32: error: expected ';' before '::' token
   11 |         return p->template A<T>::a();
      |                                ^~
      |                                ;
main.cc:11:34: error: '::a' has not been declared
   11 |         return p->template A<T>::a();
      |                                  ^
main.cc: In instantiation of 'int B<T>::b(A<T>*) [with T = int]':
main.cc:18:18:   required from here
main.cc:11:28: error: 'A' is not a member template function
   11 |         return p->template A<T>::a();
      |                ~~~~~~~~~~~~^~~~

This code successfully compiles on new versions of clang, icc and msvc as well
as gcc versions before 7.2.

Reply via email to