https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124304
Bug ID: 124304
Summary: [13/14/15/16 Regression] missing diagnostic for
mismatched dependent friend declaration to member
function template
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: attackerj1113 at gmail dot com
Target Milestone: ---
Starting with GCC 13.1, this code is incorrectly accepted (no diagnostic),
while Clang / EDG / MSVC correctly reject it
see:https://godbolt.org/z/n9v13fo4h
code:
===================================
template<typename T> class A
{
friend int T::foo();
public:
static int i;
};
struct B
{
template<class U>
void foo(U) { A<B>::i; }
};
int main() {
B b;
b.foo(0);
return 0;
}
===================================
The bug is that friend int T::foo(); has no matching declaration in T: T only
provides a void member function template foo(U), not an int foo() member.