I understand what you are saying here. The only reasonable fix I see
is to add a friend_p parameter to pushdecl, pushdecl_namespace_level,
pushdecl_with_scope, pushdecl_class_level, and maybe a couple of
others. Then we unambiguously know that we are dealing with a friend
declaration, and can set DECL_ANTICIPATED reliably. Then we need to
be able to distinguish an anticipated friend declaration from an
anticipated builtin declaration without relying on DECL_FRIEND_P.
Since it would seem to be possible (if strange) to declare a builtin
function as a friend, we can't use !DECL_BUILT_IN. So I think we
might need a new bit in lang_decl_flags (unless we can overload an
existing one which is never set for a FUNCTION_DECL, although I don't
see one at first glance).
I will modify the patch along those lines if you think that would be
better.