Topic: if (anIOstream) ... legal?
Author: Chris Riesbeck <riesbeck@ils.nwu.edu>
Date: Wed, 6 Sep 2000 01:00:38 GMT Raw View
In article <1H3o9uApnks5EwbF@ntlworld.com>, Francis Glassborow
<francisG@robinton.demon.co.uk> wrote:
>In article <riesbeck-C63AED.12324701092000@news.acns.nwu.edu>, Chris
>Riesbeck <riesbeck@ils.nwu.edu> writes
>>I think the bug is that both VC and CW define operator bool() in
>><istream> and <ostream>.
>
>I most sincerely hope that they do no such thing. If they did:
>
>int i =2;
>cin << i;
>
>would be well-formed code, and both would be required to compile it.
My error. Things like the above is why I thought operator bool() would
be simply wrong.
However operator bool() is defined in a nested sentry class for both.
Of course, now I'm back to confused as to why both say there's an
ambiguous conversion for an fstream (or stringstream) foo in
if (foo)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Sebastian Moleski" <sebmol@gmx.net>
Date: Wed, 6 Sep 2000 11:40:09 CST Raw View
"Chris Riesbeck" <riesbeck@ils.nwu.edu>:
...
> Of course, now I'm back to confused as to why both say there's an
> ambiguous conversion for an fstream (or stringstream) foo in
>
> if (foo)
Because both are not actually know for their standard compliance. Borland
C++, Comeau, and gcc are much better in that regard. The problem is always
the difference between what the Standard says a compiler should do and what
a compiler actually does.
Regards,
Sebastian Moleski
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Chris Riesbeck <riesbeck@ils.nwu.edu>
Date: Fri, 1 Sep 2000 12:31:09 GMT Raw View
I've had both VC++ 6 and Codewarrior reject
fstream foo(...);
if (foo) ...
and
stringstream foo(...);
if (foo) ...
because the if (foo) requires an ambiguous conversion.
Is that true or is it a compiler bug?
They're happy if foo is an istream or ostream, so I assume
the problem is the multiple inheritance that iostream has.
I couldn't find any description of this limitation in
Josutti. I looked at all the passages in the standard
(the real one) involving iostream and fstream and didn't
see anything. I'm still trying to work out on the resolution
rule stuff.
Note: the following are accepted with fstream and stringstream:
if (! foo) ...
and
if (foo << ...) ...
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Dietmar Kuehl <dietmar_kuehl@yahoo.com>
Date: Fri, 1 Sep 2000 13:24:30 GMT Raw View
Hi,
In article <riesbeck-ADF0A0.18152231082000@news.acns.nwu.edu>,
Chris Riesbeck <riesbeck@ils.nwu.edu> wrote:
> fstream foo(...);
> if (foo) ...
> because the if (foo) requires an ambiguous conversion.
I think this should not beambiguous and it compiles fine using
gcc-2.95.2 (and my library implementation).
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Chris Riesbeck <riesbeck@ils.nwu.edu>
Date: Sun, 3 Sep 2000 12:26:34 GMT Raw View
In article <8ooa7r$far$1@nnrp1.deja.com>, Dietmar Kuehl
<dietmar_kuehl@yahoo.com> wrote:
>Hi,
>In article <riesbeck-ADF0A0.18152231082000@news.acns.nwu.edu>,
> Chris Riesbeck <riesbeck@ils.nwu.edu> wrote:
>> fstream foo(...);
>> if (foo) ...
>
>> because the if (foo) requires an ambiguous conversion.
>
>I think this should not beambiguous and it compiles fine using
>gcc-2.95.2 (and my library implementation).
GCC with it's own library also works.
I think the bug is that both VC and CW define operator bool()
in <istream> and <ostream>. This takes priority in the above
context over the operator void*() defined in ios. Unfortunately,
for iostreams, operator bool() is ambiguous.
The other cases work for different reasons:
if (!foo) invokes operator!() which they define in ios
if (foo << ...) has type ostream which gets its operator bool()
Followup question: Is operator bool() legal at all here?
Clearly it shouldn't be in <istream> or <ostream>, but should
it even be in the base ios?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]