Boost C++ Libraries: Ticket #11998: Static const variables cannot be logged https://svn.boost.org/trac10/ticket/11998 <p> Static const variables cannot be logged for me any more. I am using RHEL 7.1 and the Intel icpc for my programms (boost compiled with gcc 4.8.3) </p> <p> The following code does not work in 1.60.0 but does in 1.59.0 Maybe it has to do with the changes regarding formatting_ostream <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/11549" title="#11549: Bugs: ostream&amp; operator&lt;&lt; overload no longer picked up by boost log (closed: fixed)">#11549</a> or <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/11545" title="#11545: Bugs: Sentry problem (closed: fixed)">#11545</a> </p> <p> Code: </p> <pre class="wiki">/* * File: main.cpp * Author: hschall * * Created on February 18, 2016, 6:53 AM */ #include &lt;cstdlib&gt; #define BOOST_LOG_DYN_LINK #include &lt;boost/log/trivial.hpp&gt; class TestStaticError{ public: static void doLog(){ BOOST_LOG_TRIVIAL(debug) &lt;&lt; myVar; } private: static const unsigned int myVar = 1337; }; class TestStaticWorking{ public: static void doLog(){ BOOST_LOG_TRIVIAL(debug) &lt;&lt; (unsigned int)myVar; } private: static const unsigned int myVar = 1337; }; using namespace std; /* * */ int main(int argc, char** argv){ TestStaticWorking::doLog(); // Works // Works in 1.59.0 //TestStaticError::doLog(); // main.cpp:21: undefined reference to `TestStaticError::myVar' return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11998 Trac 1.4.3 Andrey Semashev Thu, 18 Feb 2016 10:02:04 GMT <link>https://svn.boost.org/trac10/ticket/11998#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11998#comment:1</guid> <description> <p> I don't think this is a bug in the library. </p> <p> The static constant members have to be defined in some (one) translation unit, which gives them storage. In C++11 and later this is required if a reference to the variable is taken, which happens when you call the <code>operator&lt;&lt;</code>. In pre-C++11 versions of the language, IIRC, the definition is required unconditionally. </p> <p> The type conversion that you use as a workaround makes the <code>operator&lt;&lt;</code> bind the reference to a temporary, that's why it works. I'm not sure how it works differently in 1.59 since I don't see any changes that could lead to that but there were such changes since 1.58 - the <code>operator&lt;&lt;</code> overloads could have been chosen differently before, which would result in not taking the reference. </p> <p> However, I can see that your use case could be useful, and I'll see if I can support it in the future. </p> </description> <category>Ticket</category> </item> <item> <author>Hendrik Schall <torres@…></author> <pubDate>Thu, 18 Feb 2016 10:34:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11998#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11998#comment:2</guid> <description> <p> The workaround is just to show that this behaviour relates to the static variable. </p> <p> I compile with C++11 (but tested it also with C++98 and C++14). I did test it with the GCC (4.8.3) now aswell, same behaviour. </p> <p> Wether it is a bug or not, it depends on the boost library version, which is strange. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>o.z</dc:creator> <pubDate>Sun, 25 Sep 2016 12:42:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11998#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11998#comment:3</guid> <description> <p> I see similar problem using bitfields: </p> <p> I took the example from <a href="http://www.boost.org/doc/libs/1_61_0/libs/log/example/doc/tutorial_trivial_flt.cpp">http://www.boost.org/doc/libs/1_61_0/libs/log/example/doc/tutorial_trivial_flt.cpp</a> and added a bitfield print: </p> <pre class="wiki">#include &lt;boost/log/core.hpp&gt; #include &lt;boost/log/trivial.hpp&gt; #include &lt;boost/log/expressions.hpp&gt; namespace logging = boost::log; //[ example_tutorial_trivial_with_filtering void init() { logging::core::get()-&gt;set_filter ( logging::trivial::severity &gt;= logging::trivial::info ); } struct BF { unsigned int b : 8; BF() : b(0) {} }; int main(int, char*[]) { init(); BF bf; BOOST_LOG_TRIVIAL(info) &lt;&lt; "An informational severity message " &lt;&lt; bf.b; return 0; } //] </pre><p> With boost 1.60 I got a compilation error: </p> <pre class="wiki">cannot bind bitfield 'bf.BF::b' to 'unsigned int&amp;' </pre><p> With boost 1.57 the code is compiled and run (prints: [2016-09-19 20:21:33.018112] [0x000007fd1d5be672] [info] An informational severity message 0) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Sat, 08 Oct 2016 19:31:09 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11998#comment:4 https://svn.boost.org/trac10/ticket/11998#comment:4 <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> Should be fixed in <a class="ext-link" href="https://github.com/boostorg/log/commit/ea486c1468589b590a78ab88686dbc28ef2c91f5"><span class="icon">​</span>https://github.com/boostorg/log/commit/ea486c1468589b590a78ab88686dbc28ef2c91f5</a>. Thanks for the report. </p> Ticket