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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2017-08-25
                 CC|                            |egallager at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #5 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #1)
> You forgot to mark your operator bool as explicit.

That's bug 60135, I think.

(In reply to mqi30097 from comment #0)
> 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.

I get a warning:

$ /usr/local/bin/g++ -c -Wall -Wextra -pedantic -Weffc++ -std=c++11 63458.cc
63458.cc: In function ‘int main()’:
63458.cc:29:12: warning: ‘ch’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
  while (ms >> ch) {             // WHY NO WARNING?
         ~~~^~~~~
$

(In reply to Marek Polacek from comment #4)
> Yeah, shifting booleans is a weird thing to do.  So is multiplication or
> dividing booleans - and we don't warn on that either.

Yeah I'd expect -Wbool-operation to catch it, but it doesn't. So confirmed that
-Wbool-operation could be improved.

Reply via email to