Boost C++ Libraries: Ticket #10947: serialization singleton & sanitizer : null reference https://svn.boost.org/trac10/ticket/10947 <p> Hi all, </p> <p> I ran clang (3.5.1) sanitizer on my program and got the following error: </p> <pre class="wiki">boost/1_56_0/gcc-4.8.2/include/boost/serialization/singleton.hpp:132:13: runtime error: reference binding to null pointer of type 'const Foo' </pre><p> the program is : </p> <pre class="wiki">#include&lt;boost/serialization/singleton.hpp&gt; #include &lt;string&gt; #include &lt;iostream&gt; class Foo{ private: std::string bar = "Hello World"; public: void print() const{ std::cout &lt;&lt; bar &lt;&lt; std::endl; } }; int main(){ boost::serialization::singleton&lt;Foo&gt; test; test.get_const_instance().print(); } </pre><p> <a class="ext-link" href="http://stackoverflow.com/questions/28063066/boost-serialization-singleton-and-sanitizer-null-reference"><span class="icon">​</span>http://stackoverflow.com/questions/28063066/boost-serialization-singleton-and-sanitizer-null-reference</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10947 Trac 1.4.3 Robert Ramey Sat, 23 May 2015 23:41:15 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10947#comment:1 https://svn.boost.org/trac10/ticket/10947#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">invalid</span> </li> </ul> <p> I wasn't able to get the (address?) sanitizer working in my Xcode 6 environment. But I did trace through the program with the debugger. line 132 of singleton.hpp contains the line </p> <pre class="wiki">use(instance); </pre><p> where the value of instance has the (initialized value of zero). This might be considered an error by the sanitizer, but use(...) is an empty function. It is only included to guarantee that the singleton is called before main. If this isn't included, compile for release may optimize away the pre-main invocation and the class may not function as intended. So I would call this an over zealous behavior of the sanitizer. Or maybe the sanitizer could be considered not smart enough to trace one more level deep. or... what ever. </p> Ticket