Boost C++ Libraries: Ticket #1574: operator<< for boost::posix_time::ptime ignores ostream flags https://svn.boost.org/trac10/ticket/1574 <p> Consider the following: </p> <pre class="wiki">boost::posix_time::ptime a; cout &lt;&lt; "one " &lt;&lt; 1 &lt;&lt; endl; cout.clear(ios::failbit); cout &lt;&lt; "two " &lt;&lt; 2 &lt;&lt; endl; cout &lt;&lt; "time " &lt;&lt; a &lt;&lt; endl; cout &lt;&lt; "three" &lt;&lt; 3 &lt;&lt; endl; cout.clear(ios::goodbit); cout &lt;&lt; "four " &lt;&lt; 4 &lt;&lt; endl; </pre><p> Since cout should not produce output when ios::failbit is set, one would expect the output to be: </p> <pre class="wiki">one 1 four 4 </pre><p> However, the output is: </p> <pre class="wiki">one 1 not-a-date-timefour 4 </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1574 Trac 1.4.3 christian.stimming@… Mon, 07 Jun 2010 09:24:29 GMT version changed https://svn.boost.org/trac10/ticket/1574#comment:1 https://svn.boost.org/trac10/ticket/1574#comment:1 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.34.1</span> → <span class="trac-field-new">Boost 1.43.0</span> </li> </ul> <p> I second this bug. The error still exists in boost-1.43.0. I'll attach a test case and a patch that fixes the bug by querying ostream::fail() before doing anything in the operator&lt;&lt;. </p> Ticket christian.stimming@… Mon, 07 Jun 2010 09:26:01 GMT attachment set https://svn.boost.org/trac10/ticket/1574 https://svn.boost.org/trac10/ticket/1574 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ptime-operator.cpp</span> </li> </ul> <p> Test case for this bug: Due to the error, in the second line the date still appears even though it shouldn't have been printed because of the ios::failbit. </p> Ticket christian.stimming@… Mon, 07 Jun 2010 09:26:47 GMT attachment set https://svn.boost.org/trac10/ticket/1574 https://svn.boost.org/trac10/ticket/1574 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">fix-ptime-operator-bug1574.patch</span> </li> </ul> <p> Patch for fixing this bug by querying ostream::fail() before doing anything in the operator&lt;&lt; of ptime and time_duration </p> Ticket christian.stimming@… Mon, 07 Jun 2010 09:45:18 GMT attachment set https://svn.boost.org/trac10/ticket/1574 https://svn.boost.org/trac10/ticket/1574 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">fix-ptime-operator-2nd-bug1574.patch</span> </li> </ul> <p> Better patch for this error which (after reading my Stroustrup again) is using the ostream's sentry constructor to check for potential failbits. </p> Ticket Katie Chan Mon, 07 Jun 2010 23:00:01 GMT type changed https://svn.boost.org/trac10/ticket/1574#comment:2 https://svn.boost.org/trac10/ticket/1574#comment:2 <ul> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Patches</span> </li> </ul> Ticket Katie Chan Thu, 02 Dec 2010 06:01:50 GMT <link>https://svn.boost.org/trac10/ticket/1574#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1574#comment:3</guid> <description> <p> The most recent patch when applied to 1.45 does not produce the "expected output". </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Katie Chan</dc:creator> <pubDate>Thu, 02 Dec 2010 06:02:38 GMT</pubDate> <title>type changed https://svn.boost.org/trac10/ticket/1574#comment:4 https://svn.boost.org/trac10/ticket/1574#comment:4 <ul> <li><strong>type</strong> <span class="trac-field-old">Patches</span> → <span class="trac-field-new">Bugs</span> </li> </ul> Ticket christian.stimming@… Tue, 21 Dec 2010 13:18:51 GMT <link>https://svn.boost.org/trac10/ticket/1574#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1574#comment:5</guid> <description> <p> I don't understand ktchan's comment here. When compiling the attached example <code>ptime-operator.cpp</code> with any current boost (1.43, 1.45, SVN trunk; it doesn't matter which one), the output is </p> <pre class="wiki">Should appear: Text. And Date: 2010-Dec-21 14:12:24.398138 Boost v104300 2010-Dec-21 14:12:24.398138 This line should appear (but no single date above): Text. And Date: 2010-Dec-21 14:12:24.398138 </pre><p> which is erroneous - the second line should have been empty. After applying the attached second patch <code>fix-ptime-operator-2nd-bug1574.patch</code>, the output is </p> <pre class="wiki">Should appear: Text. And Date: 2010-Dec-21 14:12:32.328110 Boost v104300 This line should appear (but no single date above): Text. And Date: 2010-Dec-21 14:12:32.328110 </pre><p> which is the correct and expected output. Can you please apply the patch? </p> </description> <category>Ticket</category> </item> <item> <author>christian.stimming@…</author> <pubDate>Tue, 21 Dec 2010 13:19:48 GMT</pubDate> <title>version, type changed https://svn.boost.org/trac10/ticket/1574#comment:6 https://svn.boost.org/trac10/ticket/1574#comment:6 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.43.0</span> → <span class="trac-field-new">Boost 1.45.0</span> </li> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Patches</span> </li> </ul> Ticket Katie Chan Tue, 21 Dec 2010 17:27:10 GMT <link>https://svn.boost.org/trac10/ticket/1574#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1574#comment:7</guid> <description> <p> Hmm, my bad. I swear that when I tested it last time round, the output wasn't what was expected. :? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Rob Stewart</dc:creator> <pubDate>Thu, 13 Jan 2011 12:57:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1574#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1574#comment:8</guid> <description> <p> The patch looks good except for the ill-formed identifiers with double underscores. I also find "cerb" to be nonsensical. The following changes would be better: </p> <p> Instead of: </p> <pre class="wiki">typedef std::basic_ostream&lt;CharT, TraitsT&gt; __ostream_type; typename __ostream_type::sentry cerb(os); if (cerb) </pre><p> Use this: </p> <pre class="wiki">typename std::basic_ostream&lt;CharT, TraitsT&gt;::sentry ready(os); if (ready) </pre> </description> <category>Ticket</category> </item> <item> <author>christian.stimming@…</author> <pubDate>Thu, 13 Jan 2011 15:34:23 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1574#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1574#comment:9</guid> <description> <p> Feel free to commit the patch in the changed form you explained. However, the form I submitted was copied verbatim from gcc's STL, on Linux available in the file /usr/include/c++/4.4/bits/ostream_insert.h line 77ff. </p> <p> I don't know specific reasons for choosing the form I copied from there, so feel free to implement it differently in boost. But if you ask me, I'd stick to the form proposed by gcc's STL. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Thu, 13 Jan 2011 18:26:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1574#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1574#comment:10</guid> <description> <p> The reason the STL uses is exactly the reason that we can't use it. Identifiers containing a double underscore are reserved to the implementation (i.e. the compiler and standard library) for any use. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Dean Michael Berris</dc:creator> <pubDate>Mon, 31 Jan 2011 14:07:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1574#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1574#comment:11</guid> <description> <p> After looking at the ticket comments above I've made some modifications to make it a little more palatable playing nicely with the standard's forbidding the use of double underscores in identifiers that are not defined by the implementation. Please see the attached new modified patch. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Dean Michael Berris</dc:creator> <pubDate>Mon, 31 Jan 2011 14:09:02 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/1574 https://svn.boost.org/trac10/ticket/1574 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost-date_time-1574.patch</span> </li> </ul> <p> Applies cleanly to trunk 68583 </p> Ticket christian.stimming@… Fri, 23 Mar 2012 09:08:08 GMT <link>https://svn.boost.org/trac10/ticket/1574#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1574#comment:12</guid> <description> <p> Error still present in boost-1.46 and also still SVN trunk. Any news on applying the patch? </p> </description> <category>Ticket</category> </item> <item> <author>christian.stimming@…</author> <pubDate>Thu, 10 Jan 2013 10:20:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1574#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1574#comment:13</guid> <description> <p> Error still present in boost-1.52 and also still SVN trunk. Any news on applying the patch? </p> </description> <category>Ticket</category> </item> <item> <author>christian.stimming@…</author> <pubDate>Thu, 24 Oct 2013 11:10:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1574#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1574#comment:14</guid> <description> <p> Error still present in boost-1.53 and also still SVN trunk. Any news on applying the patch? </p> </description> <category>Ticket</category> </item> </channel> </rss>