https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120130
Bug ID: 120130
Summary: Cannot declare function template as friend in the
presence of same named member function
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fchelnokov at gmail dot com
Target Milestone: ---
This program:
```
template<typename T>
struct Foo;
template<typename T>
void g(const Foo<T>&) {}
template<typename T>
struct Foo {
Foo g() { return *this; }
friend void g<>(const Foo<T>&);
};
int main() {
Foo<int>{}.g();
g(Foo<int>{});
}
```
is accepted by Clang, but GCC rejects it with
> error: template-id 'g<>' for 'void g(const Foo<int>&)' does not match any
> template declaration
Online demo: https://gcc.godbolt.org/z/fE9Eeoabz
Note that swapping the lines inside struct Foo makes GCC happy as well.
Found in https://stackoverflow.com/q/79607696/7325599