Topic: std::ios_base::iostate err=0;


Author: Steve Clamage <clamage@eng.sun.com>
Date: Sun, 14 Oct 2001 22:08:08 GMT
Raw View
On Tue, 9 Oct 2001, Helmut Zeisel wrote:
>
> Must this code compile?
>
> std::ios_base::iostate err=0;

No.
>
> GCC 3.0.1 insists says
> "cannot convert `int' to `std::_Ios_Iostate' in initialization".

That's allowed.

>
> This line works:
>
> std::ios_base::iostate err=std::ios_base::goodbit;

Yes, it must.

The standard allows iostate to be implemented as an integer,
as an enumated type that overloads some arithmetic operations,
or as a bitset. There is no requirement that you be able to
assign an integer value to it.

Refer to C++ standard, 27.4.2.1.3 "Type ios_base::iostate" and
17.3.2.1.2 "Bitmask types".

--
Steve Clamage, stephen.clamage@sun.com

---
[ 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://www.research.att.com/~austern/csc/faq.html                ]





Author: Helmut Zeisel <helmut.zeisel@vai.at>
Date: Tue, 9 Oct 2001 18:05:25 GMT
Raw View
Must this code compile?

std::ios_base::iostate err=0;

GCC 3.0.1 insists says
"cannot convert `int' to `std::_Ios_Iostate' in initialization".

This line works:

std::ios_base::iostate err=std::ios_base::goodbit;

Is the behavior of GCC 3.0.1 standard conform?

Helmut

---
[ 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://www.research.att.com/~austern/csc/faq.html                ]





Author: Ron Natalie <ron@sensor.com>
Date: Tue, 9 Oct 2001 18:55:33 GMT
Raw View

Helmut Zeisel wrote:
>
> Must this code compile?
>
> std::ios_base::iostate err=0;
>
> GCC 3.0.1 insists says
> "cannot convert `int' to `std::_Ios_Iostate' in initialization".
>
> This line works:
>
> std::ios_base::iostate err=std::ios_base::goodbit;
>
> Is the behavior of GCC 3.0.1 standard conform?
>
iostate is a bitmask, which is an enum type (with some additional helpers).
Integers (even zero) do not convert implicitly to enum type.  You'll have to
cast it.

There is even an example in the C++ standard that is wrong (21.1.1/3).
If you want to do this you want to assign "goodbit"

 std::ios_base::iostate = std::ios_base::goodbit;

-Ron
Welcome to Good Bit home of the Good Bit.

---
[ 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://www.research.att.com/~austern/csc/faq.html                ]





Author: Pete Becker <petebecker@acm.org>
Date: Tue, 9 Oct 2001 19:09:27 GMT
Raw View
Ron Natalie wrote:
>
> >
> iostate is a bitmask, which is an enum type (with some additional helpers).

A bitmask type can be an enumerated type with overloaded operators, an
integer type, or a bitset. Which doesn't change the fact that 0 isn't an
appopriate initializer...

> Integers (even zero) do not convert implicitly to enum type.  You'll have to
> cast it.
>
> There is even an example in the C++ standard that is wrong (21.1.1/3).
> If you want to do this you want to assign "goodbit"
>
>         std::ios_base::iostate = std::ios_base::goodbit;
>
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ 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://www.research.att.com/~austern/csc/faq.html                ]





Author: Helmut Zeisel <helmut.zeisel@aon.at>
Date: Tue, 9 Oct 2001 20:35:44 GMT
Raw View
Ron Natalie wrote:
>
> Helmut Zeisel wrote:
> >
> > Must this code compile?
> >
> > std::ios_base::iostate err=0;
> >

>
> There is even an example in the C++ standard that is wrong (21.1.1/3).

I think you mean 22.1.1/3
Similar code is also in 27.6.1.2.2

This was why I thought that GCC might be wrong.
As I understand now these are typos in the standard and GCC is right.

Helmut

---
[ 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://www.research.att.com/~austern/csc/faq.html                ]