https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108020
Bug ID: 108020 Summary: Add fix-it hint for iostream operators declared in-class without 'friend' Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: diagnostic Severity: enhancement Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- #include <istream> #include <ostream> struct S { std::istream& operator>>(std::istream&, S&); std::ostream& operator<<(std::ostream&, S&); }; streamop.cc:5:17: error: ‘std::istream& S::operator>>(std::istream&, S&)’ must have exactly one argument 5 | std::istream& operator>>(std::istream&, S&); | ^~~~~~~~ streamop.cc:6:17: error: ‘std::ostream& S::operator<<(std::ostream&, S&)’ must have exactly one argument 6 | std::ostream& operator<<(std::ostream&, S&); | ^~~~~~~~ The user probably meant to declare these with 'friend'. We could suggest that in a fix-it hint. The fix-it should only be given when the first argument is a specialization of std::basic_[io]stream. The error is fine for shift operators, although those are probably defined less often than stream operators. The fix-it could be added if the signature of a member function matches either of these, for any C and T: std::basic_ostream<C,T>& operator<<(std::basic_ostream<C,T>&, const X&); std::basic_istream<C,T>& operator>>(std::basic_istream<C,T>&, X&);