Boost C++ Libraries: Ticket #13430: boost::optional C++98 and C++11 compatability breaks in boost 1.66.0 https://svn.boost.org/trac10/ticket/13430 <p> Hi, </p> <p> I have an application that links both C++98 and C++11 libraries, this has worked fine up to and including boost 1.65.1 </p> <p> The issue is caused by a shared header from the C++98 library that uses boost::optional, when compiled by the C++11 code it gets a different class layout of boost::optional to the C++98 code and this is causing binary incompatibilities and seg faults. </p> <p> Observed on both a Mac with clang 9.0.0 and RHEL with gcc 4.8.5. Windows does not have this issue. </p> <p> A simple example is a C++98 class Test98 as follows (test98.hpp) </p> <pre class="wiki">#include &lt;boost/optional.hpp&gt; class Test98 { public: Test98 (boost::optional&lt;bool&gt; o = boost::none); private: boost::optional&lt;bool&gt; o_; }; </pre><p> with implementation (test98.cpp) </p> <pre class="wiki">#include "test98.hpp" Test98::Test98 (boost::optional&lt;bool&gt; o) : o_(o) {} </pre><p> Then a main program (main11.cpp) </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/make_shared.hpp&gt; int main () { boost::shared_ptr&lt;Test98&gt; t98 = boost::make_shared&lt;Test98&gt;(); std::cout &lt;&lt; "OK" &lt;&lt; std::endl; return 0; } </pre><p> When I compile test98.cpp as C++98 and main11.cpp as C++11, e.g. with a Makefile </p> <pre class="wiki">boost=/Users/niall/dev/boost_1_66_0 all: main11 clean: rm *.o main11 test98.o: test98.cpp g++ -c -Wall -g -O0 -I${boost} $&lt; -o $@ main11.o: main11.cpp g++ -c -std=c++11 -g -O0 -Wall -I${boost} $&lt; -o $@ main11: main11.o test98.o g++ $^ -o $@ </pre><p> it causes a seg fault, in a debugger I can see the problem is the boost::optional constructor at optional.hpp:946 </p> <pre class="wiki"> 945 #else -&gt; 946 optional ( optional const&amp; rhs ) : base( static_cast&lt;base const&amp;&gt;(rhs) ) {} 947 #endif </pre><p> One might argue that it is wrong to attempt to mix 98 and 11 like this, the two preprocessor runs above are generating different versions of test98.hpp, but it works previously so is a regression issue for me. </p> <p> Regards, Niall. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13430 Trac 1.4.3