This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ Patch] PR 59480 ("Missing error diagnostic: friend declaration specifying a default argument must be a definition")​ (Take 2)


Hi,

thus, as you may or may not have noticed I reverted my first try, when Tobias noticed that in his large codebase we were rejecting code like:

class Matrix;

Matrix rot90 (const Matrix& a, int k = 1);

class Matrix {
  friend Matrix rot90 (const Matrix&, int);
};

Matrix rot90 (const Matrix& a, int k) { return Matrix(); }

this was happening because, when duplicate_decls saw the friend declaration, smashed together the first two rot90 declaration and we ended up with a friend declaration with defaults (taken from the first rot90 declaration), as such rejected the third time we saw rot90. I think we can elegantly handle this kind of problem by exploiting the DECL_HIDDEN_FRIEND_P information, thus, in check_no_redeclaration_friend_default_args, as called by duplicate_decls, if the newdecl doesn't have DECL_FRIEND_P set, disregard an olddecl which doesn't have DECL_HIDDEN_FRIEND_P set (we can't do this directly because duplicate_decls is already smashing decls together at that point, thus we need to save the info and pass it as an argument). I added quite a few additional tests an also asked Tobias to double check on his code base. All good.

As a general arguments of why I think moving from DECL_FRIEND_P to DECL_HIDDEN_FRIEND_P for the olddecl is the right thing to do, if the olddecl is a friend but doesn't have DECL_HIDDEN_FRIEND_P set, there was a declaration preceding it, thus, either the friend declaration has default arguments and we already diagnosed that, or it doesn't , thus isn't interesting anymore for the diagnostic at issue.

Thanks! Paolo.

///////////////////////////

Attachment: CL_59480_2
Description: Text document

Attachment: patch_59480_2
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]