Boost C++ Libraries: Ticket #11918: access violation when using string literals with lambda style formatting expressions https://svn.boost.org/trac10/ticket/11918 <p> The code below crashes with an access violation when using the BOOST_LOG_SEV macro. I'm using boost 1.60 compiled with msvc-10.0. </p> <div class="wiki-code"><div class="code"><pre> <span class="cp">#include</span> <span class="cpf">&lt;boost/log/trivial.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/log/sinks.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/log/expressions.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/log/expressions/formatters.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/log/attributes.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/core/null_deleter.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#define BOOST_TEST_MODULE TestsLogging</span> <span class="cp">#include</span> <span class="cpf">&lt;boost/test/unit_test.hpp&gt;</span><span class="cp"></span> <span class="n">BOOST_AUTO_TEST_SUITE</span><span class="p">(</span><span class="n">example_lib_log</span><span class="p">)</span> <span class="n">BOOST_AUTO_TEST_CASE</span><span class="p">(</span><span class="n">severity_logging_min</span><span class="p">)</span> <span class="p">{</span> <span class="k">namespace</span> <span class="n">src</span> <span class="o">=</span> <span class="o">::</span><span class="n">boost</span><span class="o">::</span><span class="n">log</span><span class="o">::</span><span class="n">sources</span><span class="p">;</span> <span class="k">namespace</span> <span class="n">keywords</span> <span class="o">=</span> <span class="o">::</span><span class="n">boost</span><span class="o">::</span><span class="n">log</span><span class="o">::</span><span class="n">keywords</span><span class="p">;</span> <span class="k">namespace</span> <span class="n">expr</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">log</span><span class="o">::</span><span class="n">expressions</span><span class="p">;</span> <span class="k">namespace</span> <span class="n">attributes</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">log</span><span class="o">::</span><span class="n">attributes</span><span class="p">;</span> <span class="c1">//sink backend setup</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">log</span><span class="o">::</span><span class="n">sinks</span><span class="o">::</span><span class="n">text_ostream_backend</span> <span class="n">text_ostream_backend</span><span class="p">;</span> <span class="n">boost</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">text_ostream_backend</span><span class="o">&gt;</span> <span class="n">backend</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">make_shared</span><span class="o">&lt;</span><span class="n">text_ostream_backend</span><span class="o">&gt;</span><span class="p">();</span> <span class="n">backend</span><span class="o">-&gt;</span><span class="n">add_stream</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">ostream</span><span class="o">&gt;</span><span class="p">(</span><span class="o">&amp;</span><span class="n">std</span><span class="o">::</span><span class="n">cerr</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">null_deleter</span><span class="p">()));</span> <span class="n">backend</span><span class="o">-&gt;</span><span class="n">auto_flush</span><span class="p">(</span><span class="nb">true</span><span class="p">);</span> <span class="c1">//sink frontend setup</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">log</span><span class="o">::</span><span class="n">sinks</span><span class="o">::</span><span class="n">synchronous_sink</span><span class="o">&lt;</span><span class="n">text_ostream_backend</span><span class="o">&gt;</span> <span class="n">synchronous_sink_text_ostream_backend</span><span class="p">;</span> <span class="n">boost</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">synchronous_sink_text_ostream_backend</span><span class="o">&gt;</span> <span class="n">sink</span><span class="p">(</span><span class="k">new</span> <span class="n">synchronous_sink_text_ostream_backend</span><span class="p">(</span><span class="n">backend</span><span class="p">));</span> <span class="n">sink</span><span class="o">-&gt;</span><span class="n">set_formatter</span><span class="p">(</span><span class="n">expr</span><span class="o">::</span><span class="n">stream</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;[&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">expr</span><span class="o">::</span><span class="n">message</span><span class="p">);</span> <span class="c1">//problem is here</span> <span class="n">boost</span><span class="o">::</span><span class="n">log</span><span class="o">::</span><span class="n">core</span><span class="o">::</span><span class="n">get</span><span class="p">()</span><span class="o">-&gt;</span><span class="n">add_sink</span><span class="p">(</span><span class="n">sink</span><span class="p">);</span> <span class="c1">//logger setup</span> <span class="k">typedef</span> <span class="n">src</span><span class="o">::</span><span class="n">severity_logger</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">log</span><span class="o">::</span><span class="n">trivial</span><span class="o">::</span><span class="n">severity_level</span><span class="o">&gt;</span> <span class="n">severity_logger</span><span class="p">;</span> <span class="n">severity_logger</span> <span class="n">lg</span><span class="p">;</span> <span class="c1">//logging function</span> <span class="n">BOOST_LOG_SEV</span><span class="p">(</span><span class="n">lg</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">log</span><span class="o">::</span><span class="n">trivial</span><span class="o">::</span><span class="n">debug</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;First entry.&quot;</span><span class="p">;</span> <span class="c1">//exception happens here</span> <span class="n">boost</span><span class="o">::</span><span class="n">log</span><span class="o">::</span><span class="n">core</span><span class="o">::</span><span class="n">get</span><span class="p">()</span><span class="o">-&gt;</span><span class="n">remove_sink</span><span class="p">(</span><span class="n">sink</span><span class="p">);</span> <span class="p">}</span> <span class="n">BOOST_AUTO_TEST_SUITE_END</span><span class="p">()</span> </pre></div></div><ul><li>When I remove the line where the formatter for the sink is set, the code works fine. </li><li>When I remove the string literal "[" from the stream (expr::stream &lt;&lt; expr::message), the code works fine. </li><li>When i move the string literal to the end (expr::stream &lt;&lt; expr::message &lt;&lt; "[") the code also works. </li><li>The code works with boost 1.57. </li></ul> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11918 Trac 1.4.3 Andrey Semashev Sun, 17 Jan 2016 17:20:31 GMT <link>https://svn.boost.org/trac10/ticket/11918#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11918#comment:1</guid> <description> <p> Works without a problem for me on gcc 5.2. Looks like a specific compiler issue to me. </p> </description> <category>Ticket</category> </item> <item> <author>Stefan Mianome <smianome@…></author> <pubDate>Mon, 18 Jan 2016 01:35:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11918#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11918#comment:2</guid> <description> <p> i've just tried to run it on msvc-14. It works aswell. I've found a workaround for msvc-10 that suits my needs. By passing a custom formatting function to the sinks set_formatter function, conditional formatting + string literals at the beginning of the stream are possible. I've spent 2 days to figure out that the problem is not with the code :( </p> </description> <category>Ticket</category> </item> <item> <author>Stefan Mianome <smianome@…></author> <pubDate>Mon, 18 Jan 2016 01:35:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11918#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11918#comment:2</guid> <description> <p> i've just tried to run it on msvc-14. It works aswell. I've found a workaround for msvc-10 that suits my needs. By passing a custom formatting function to the sinks set_formatter function, conditional formatting + string literals at the beginning of the stream are possible. I've spent 2 days to figure out that the problem is not with the code :( </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 18 Jan 2016 08:18:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11918#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11918#comment:3</guid> <description> <p> This got also reported on Boost.User for MSVC11: <a class="ext-link" href="http://thread.gmane.org/gmane.comp.lib.boost.user/85258"><span class="icon">​</span>http://thread.gmane.org/gmane.comp.lib.boost.user/85258</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 24 Mar 2016 15:12:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11918#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11918#comment:4</guid> <description> <p> This seems to be the same bug as <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/12025" title="#12025: Bugs: basic_usage example crashes with Visual Studio 2010 SP1 (closed: fixed)">#12025</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Thu, 24 Mar 2016 21:25:58 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11918#comment:5 https://svn.boost.org/trac10/ticket/11918#comment:5 <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">duplicate</span> </li> </ul> Ticket