Created on 2004-06-28.00:00:00 last changed 183 months ago
[ Lillehammer: Doug provided revised wording for "unspecified-bool-type". ]
[ Redmond: 5-4 straw poll in favor of doing this. ]
Proposed resolution:
Replace std::basic_ios<charT, traits>::operator void*() with another conversion operator to some unspecified type that is guaranteed not to be convertible to any other type except for bool (a pointer-to-member might be one such suitable type). In addition, make it clear that the pointer type need not be a pointer to a complete type and when non-null, the value need not be valid.
Specifically, change in [lib.ios] the signature of
operator void*() const;
to
operator unspecified-bool-type() const;
and change [lib.iostate.flags], p1 from
operator void*() const;
to
operator unspecified-bool-type() const;
-1- Returns: if fail() then a value that will evaluate false in a
boolean context; otherwise a value that will evaluate true in a
boolean context. The value type returned shall not be
convertible to int.
-2- [Note: This conversion can be used in contexts where a bool
is expected (e.g., an if condition); however, implicit
conversions (e.g., to int) that can occur with bool are not
allowed, eliminating some sources of user error. One possible
implementation choice for this type is pointer-to-member. - end
note]
The program below is required to compile but when run it typically produces unexpected results due to the user-defined conversion from std::cout or any object derived from basic_ios to void*.
#include <cassert>
#include <iostream>
int main ()
{
assert (std::cin.tie () == std::cout);
// calls std::cout.ios::operator void*()
}
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2010-10-21 18:28:33 | admin | set | messages: + msg2751 |
| 2010-10-21 18:28:33 | admin | set | messages: + msg2750 |
| 2010-10-21 18:28:33 | admin | set | messages: + msg2749 |
| 2004-06-28 00:00:00 | admin | create | |