Subject: [Boost-bugs] [Boost C++ Libraries] #13430: boost::optional C++98 and C++11 compatability breaks in boost 1.66.0
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2018-01-30 16:20:38
#13430: boost::optional C++98 and C++11 compatability breaks in boost 1.66.0
-------------------------------+-------------------------------
Reporter: nialljosullivan@⦠| Owner: Fernando Cacciola
Type: Bugs | Status: new
Milestone: To Be Determined | Component: optional
Version: Boost 1.66.0 | Severity: Regression
Keywords: |
-------------------------------+-------------------------------
Hi,
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
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.
Observed on both a Mac with clang 9.0.0 and RHEL with gcc 4.8.5. Windows
does not have this issue.
A simple example is a C++98 class Test98 as follows (test98.hpp)
{{{
#include <boost/optional.hpp>
class Test98 {
public:
Test98 (boost::optional<bool> o = boost::none);
private:
boost::optional<bool> o_;
};
}}}
with implementation (test98.cpp)
{{{
#include "test98.hpp"
Test98::Test98 (boost::optional<bool> o) : o_(o) {}
}}}
Then a main program (main11.cpp)
{{{
#include <iostream>
#include <boost/make_shared.hpp>
int main () {
boost::shared_ptr<Test98> t98 = boost::make_shared<Test98>();
std::cout << "OK" << std::endl;
return 0;
}
}}}
When I compile test98.cpp as C++98 and main11.cpp as C++11, e.g. with a
Makefile
{{{
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} $< -o $@
main11.o: main11.cpp
g++ -c -std=c++11 -g -O0 -Wall -I${boost} $< -o $@
main11: main11.o test98.o
g++ $^ -o $@
}}}
it causes a seg fault, in a debugger I can see the problem is the
boost::optional constructor at optional.hpp:946
{{{
945 #else
-> 946 optional ( optional const& rhs ) : base( static_cast<base
const&>(rhs) ) {}
947 #endif
}}}
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.
Regards,
Niall.
-- Ticket URL: <https://svn.boost.org/trac10/ticket/13430> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2018-01-30 16:26:24 UTC