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

            Bug ID: 98039
           Summary: Member function template with dependent return type
                    involving class's own name: wrong-mangling,
                    accepts-invalid
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arthur.j.odwyer at gmail dot com
  Target Milestone: ---

// https://godbolt.org/z/qq7196
struct S {
    template<class T> static void f(T);
    template<class T> static auto h(T t)
        -> decltype(S::f(t));
};
void test() {
    S::h(42);
}

Here, GCC trunk mangles `S::h` as `_ZN1S1hIiEEDTclsrS_1ffp_EET_`, but both
Clang and ICC agree that the mangling should be
`_ZN1S1hIiEEDTclsr1SE1ffp_EET_`. I naively assume that this indicates a bug in
GCC's mangling.

_ZN1S1hIiEEDTclsrS_1ffp_EET_ has "S_" where
_ZN1S1hIiEEDTclsr1SE1ffp_EET_ has "1SE".

====

It gets worse: If you make `f` non-static, then GCC accepts this code even
though it is invalid. In that case, the mangled name of the `h` that is
(wrongly) called is

_ZN1S1hIiEEDTcldtdefpTsrS_1ffp_EET_

// https://godbolt.org/z/Kr1baT
struct S {
    template<class T> void f(T);
    template<class T> static auto h(T t)
        -> decltype(S::f(t));
};
void test() {
    S::h(42);
}

Reply via email to