GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

c++: Reject friend declarations with explicit object parameters

Prevents compilation of invalid friend declarations that misuse explicit object parameters, avoiding crashes.

GCC now correctly rejects friend declarations that attempt to use explicit object parameters, a feature intended only for member functions. Previously, the compiler allowed such declarations, leading to internal errors and crashes later in the compilation process due to incorrect access checks. This fix ensures that only member functions can employ explicit object parameters, improving the robustness of C++ parsing and access control.

In Details

This commit addresses an incorrect check in grokdeclarator for non-member friend functions. Previously, it did not properly distinguish between member functions and non-member friends when an explicit object parameter (this Self&) was used, leading to ICEs. The change extends the check to cover unqualified friends and correctly sets is_xobj_member_function, ensuring such invalid constructs are diagnosed.

For Context
friend declaration
In C++, a friend declaration grants a non-member function or class access to the private and protected members of a class.
explicit object parameter
A C++ feature (introduced in C++23 as explicit(this) or explicit(this Self&) for member functions) that allows a member function to bind to an object explicitly, enabling it to be called as a non-member.
ICE
Internal Compiler Error. A fatal error during compilation that indicates a bug within the compiler itself.
Filed Under: c++friendcompile-errorsecurity