https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71755
Bug ID: 71755 Summary: friend function may not be defined inside a class using a qualified name but GCC allows that Product: gcc Version: 6.1.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ww2www2w at gmail dot com Target Milestone: --- This code should not be compiled, but GCC compiles it successfully (btw vc++ and clang report an error). #include <iostream> using namespace std; int ticket(); class Manager { friend int ::ticket() { // qualified function name return ++Manager::counter; } static int counter; }; int Manager::counter; int main() { cout << ticket(); return 0; } g++ -std=c++14 -O2 -Wall -pedantic -pthread main.cpp && ./a.out GCC should report an error because a friend function may not be defined inside a class using a qualified name (it may only be declared). See 11.3.6 in http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/n4594.pdf (or any c++ standard edition since 2003)