Boost C++ Libraries: Ticket #2103: ostream::operator<<(bool) is called if optional_io.hpp is not included https://svn.boost.org/trac10/ticket/2103 <p> If you pass an optional&lt;T&gt; value to ostream, it would print a result of safe_bool() if &lt;boost/optional/optional_io.hpp&gt; is not included. </p> <pre class="wiki">$ cat -n unspecified_bool_type.cpp 1 #include &lt;iostream&gt; 2 #include &lt;boost/optional/optional.hpp&gt; 3 4 boost::optional&lt;char&gt; o('o'); 5 6 void without_io() 7 { 8 std::cout &lt;&lt; o &lt;&lt; '\n'; 9 } 10 11 #include &lt;boost/optional/optional_io.hpp&gt; 12 13 void with_io() 14 { 15 std::cout &lt;&lt; o &lt;&lt; '\n'; 16 } 17 18 int main() 19 { 20 without_io(); 21 with_io(); 22 } $ ./a.out 1 o </pre><p> This can be fixed by a adding forward declaration of operator&lt;&lt; to optional_fwd.hpp. </p> <p> Note that other uses of unspecified_bool_type may be buggy. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2103 Trac 1.4.3 nasonov Thu, 10 Jul 2008 11:54:44 GMT attachment set https://svn.boost.org/trac10/ticket/2103 https://svn.boost.org/trac10/ticket/2103 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">2103.patch</span> </li> </ul> <p> Patch (not against the latest version in the trunk) that fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2103" title="#2103: Bugs: ostream::operator&lt;&lt;(bool) is called if optional_io.hpp is not included (closed: fixed)">#2103</a> and also fixes incorrect uses of BOOST_NO_TEMPLATED_STREAMS. </p> Ticket Steven Watanabe Sat, 16 Feb 2013 19:32:22 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2103#comment:1 https://svn.boost.org/trac10/ticket/2103#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/82930" title="Add a forward declaration of the ostream operator for optional. Fixes ...">[82930]</a>) Add a forward declaration of the ostream operator for optional. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2103" title="#2103: Bugs: ostream::operator&lt;&lt;(bool) is called if optional_io.hpp is not included (closed: fixed)">#2103</a>. </p> Ticket