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

            Bug ID: 63458
           Summary: myclassobj >> charac compiles without warning, EVEN
                    though ONLY operator>>(std::string&) exists
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mqi30097 at qoika dot com

Why no warning whatsoever??

//================= go.cpp ======================================
#include <iostream>

class Mystream
{
public:
  Mystream(std::istream& is1) : is{is1} {}
  Mystream& operator>>(std::string&);
  operator bool();
private:
  std::istream& is;
};

Mystream& Mystream::operator>>(std::string& s)
{
  is >> s;
  return *this;
}

Mystream::operator bool()
{
  return is.good();
}

int main()
{
  Mystream ms(std::cin);

  char ch;
  while (ms >> ch) {             // WHY NO WARNING?
    std::cout << ch << '\n';
  }
  return 0;
}

//================= end of go.cpp ======================================

Compile with:
c++ -std=c++11 -o go go.cpp

To "fix" the program:
Change declaration in main from 
  char ch;
to 
  std::string ch; 

Why no warning?
Thanks.

Reply via email to