public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108020] New: Add fix-it hint for iostream operators declared in-class without 'friend'
@ 2022-12-08 10:14 redi at gcc dot gnu.org
  2022-12-08 22:50 ` [Bug c++/108020] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2022-12-08 10:14 UTC (permalink / raw)
  To: gcc-bugs

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&);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/108020] Add fix-it hint for iostream operators declared in-class without 'friend'
  2022-12-08 10:14 [Bug c++/108020] New: Add fix-it hint for iostream operators declared in-class without 'friend' redi at gcc dot gnu.org
@ 2022-12-08 22:50 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-08 22:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108020

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-12-08
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-08 22:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08 10:14 [Bug c++/108020] New: Add fix-it hint for iostream operators declared in-class without 'friend' redi at gcc dot gnu.org
2022-12-08 22:50 ` [Bug c++/108020] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).