Boost C++ Libraries: Ticket #12577: Null reference in pair.hpp triggers runtime warning with -fsanitize=undefined https://svn.boost.org/trac10/ticket/12577 <p> I tagged 1.62 which is where I discovered the issue, but master at github seems affected as well. </p> <p> Consider this minimal file: </p> <pre class="wiki">#include &lt;boost/container/flat_map.hpp&gt; int main() { return 0; } </pre><p> When built with gcc 6.2 and undefined sanitizers, <code>g++ -fsanitize=address</code>, the resulting executable triggers the following warning at runtime during static initialization: </p> <pre class="wiki">/usr/include/boost/container/detail/pair.hpp:85:30: runtime error: reference binding to null pointer of type 'const struct piecewise_construct_t' </pre><p> This doesn't happen with clang 3.9, so it *might* be a bug in gcc, but when looking at the boost code, I'd say gcc is right. Indeed, in <code>container/detail/pair.hpp</code> (line 85 in 1.62 and master), the static global variable <code>boost::container::piecewise_construct</code> is defined, of type <code>const std::piecewise_construct_t &amp;</code>, and value <code>*boost::container::std_piecewise_construct_holder&lt;0&gt;::dummy</code>, defined in the same file, but (as far as I can tell), uninitialized. </p> <p> I'm not well positioned to assess the bug severity: either the null/uninitialized reference is never used, and the gcc warning can be ignored (although it's annoying); or there are situations the reference's address is dereferenced, and this can lead to crashes. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12577 Trac 1.4.3 Ion Gaztañaga Sat, 12 Nov 2016 23:20:40 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12577#comment:1 https://svn.boost.org/trac10/ticket/12577#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> Thanks for the report. </p> <p> The null value is never used, but sanitizers should work. A workaround was pushed and I confirmed it with GCC 6.2 and -fsanitize=address: </p> <p> <a class="ext-link" href="https://github.com/boostorg/container/commit/77f5d7218da42db37b4fecc97f7c389a9e6b9cd4"><span class="icon">​</span>https://github.com/boostorg/container/commit/77f5d7218da42db37b4fecc97f7c389a9e6b9cd4</a> </p> Ticket Eric Niebler Tue, 24 Jan 2017 01:56:31 GMT <link>https://svn.boost.org/trac10/ticket/12577#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12577#comment:2</guid> <description> <p> This code requires global constructors, which causes a warning on some compilers. Why isn't this simply: </p> <pre class="wiki">template &lt;class T&gt; struct static_constexpr { static constexpr T const value {}; }; template &lt;class T&gt; constexpr T const static_constexpr&lt;T&gt;::value; using piecewise_construct_t = std::piecewise_construct_t const &amp;; namespace { piecewise_construct_t piecewise_construct = static_constexpr&lt;std::piecewise_construct_t&gt;::value; } </pre><p> ?? </p> </description> <category>Ticket</category> </item> </channel> </rss>