Opened 14 years ago
Closed 10 years ago
#2103 closed Bugs (fixed)
ostream::operator<<(bool) is called if optional_io.hpp is not included
| Reported by: | nasonov | Owned by: | Fernando Cacciola |
|---|---|---|---|
| Milestone: | Boost 1.36.0 | Component: | optional |
| Version: | Boost 1.35.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
If you pass an optional<T> value to ostream, it would print a result of safe_bool() if <boost/optional/optional_io.hpp> is not included.
$ cat -n unspecified_bool_type.cpp
1 #include <iostream>
2 #include <boost/optional/optional.hpp>
3
4 boost::optional<char> o('o');
5
6 void without_io()
7 {
8 std::cout << o << '\n';
9 }
10
11 #include <boost/optional/optional_io.hpp>
12
13 void with_io()
14 {
15 std::cout << o << '\n';
16 }
17
18 int main()
19 {
20 without_io();
21 with_io();
22 }
$ ./a.out
1
o
This can be fixed by a adding forward declaration of operator<< to optional_fwd.hpp.
Note that other uses of unspecified_bool_type may be buggy.
Attachments (1)
Change History (2)
by , 14 years ago
| Attachment: | 2103.patch added |
|---|
comment:1 by , 10 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.

Patch (not against the latest version in the trunk) that fixes #2103 and also fixes incorrect uses of BOOST_NO_TEMPLATED_STREAMS.