public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/63458] New: myclassobj >> charac compiles without warning, EVEN though ONLY operator>>(std::string&) exists
@ 2014-10-04 13:35 mqi30097 at qoika dot com
2014-10-04 13:41 ` [Bug c++/63458] " glisse at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: mqi30097 at qoika dot com @ 2014-10-04 13:35 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/63458] myclassobj >> charac compiles without warning, EVEN though ONLY operator>>(std::string&) exists
2014-10-04 13:35 [Bug c++/63458] New: myclassobj >> charac compiles without warning, EVEN though ONLY operator>>(std::string&) exists mqi30097 at qoika dot com
@ 2014-10-04 13:41 ` glisse at gcc dot gnu.org
2014-10-04 13:43 ` glisse at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-10-04 13:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63458
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
You forgot to mark your operator bool as explicit.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/63458] myclassobj >> charac compiles without warning, EVEN though ONLY operator>>(std::string&) exists
2014-10-04 13:35 [Bug c++/63458] New: myclassobj >> charac compiles without warning, EVEN though ONLY operator>>(std::string&) exists mqi30097 at qoika dot com
2014-10-04 13:41 ` [Bug c++/63458] " glisse at gcc dot gnu.org
@ 2014-10-04 13:43 ` glisse at gcc dot gnu.org
2014-10-04 13:48 ` glisse at gcc dot gnu.org
2014-10-04 19:22 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-10-04 13:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63458
--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> ---
Actually, I do get a warning:
s.c:29:13: warning: 'ch' is used uninitialized in this function
[-Wuninitialized]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/63458] myclassobj >> charac compiles without warning, EVEN though ONLY operator>>(std::string&) exists
2014-10-04 13:35 [Bug c++/63458] New: myclassobj >> charac compiles without warning, EVEN though ONLY operator>>(std::string&) exists mqi30097 at qoika dot com
2014-10-04 13:41 ` [Bug c++/63458] " glisse at gcc dot gnu.org
2014-10-04 13:43 ` glisse at gcc dot gnu.org
@ 2014-10-04 13:48 ` glisse at gcc dot gnu.org
2014-10-04 19:22 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-10-04 13:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63458
--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
Though we could probably add a warning for:
int f(bool b)
{
return b>>3;
}
since it is unusual to use >> on a boolean, and it would catch your testcase.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/63458] myclassobj >> charac compiles without warning, EVEN though ONLY operator>>(std::string&) exists
2014-10-04 13:35 [Bug c++/63458] New: myclassobj >> charac compiles without warning, EVEN though ONLY operator>>(std::string&) exists mqi30097 at qoika dot com
` (2 preceding siblings ...)
2014-10-04 13:48 ` glisse at gcc dot gnu.org
@ 2014-10-04 19:22 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-10-04 19:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63458
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Yeah, shifting booleans is a weird thing to do. So is multiplication or
dividing booleans - and we don't warn on that either.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-10-04 19:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-04 13:35 [Bug c++/63458] New: myclassobj >> charac compiles without warning, EVEN though ONLY operator>>(std::string&) exists mqi30097 at qoika dot com
2014-10-04 13:41 ` [Bug c++/63458] " glisse at gcc dot gnu.org
2014-10-04 13:43 ` glisse at gcc dot gnu.org
2014-10-04 13:48 ` glisse at gcc dot gnu.org
2014-10-04 19:22 ` mpolacek 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).