Subject: Re: [boost] C++03 / C++11 compatibility question for compiled libraries
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2018-02-10 18:09:43
On 02/10/2018 03:32 AM, Raffi Enficiaud via Boost wrote:
> Le 09.02.18 Ã 20:08, Steven Watanabe via Boost a Ã©critÂ :
>> In general, I think that:
>> - interfaces that take boost/std::xxx as a parameter
>> should accept both.> - interfaces that return boost/std::xxx are hard
>> and I don't know how to handle them.
> Yes. You are starting/proposing a recipe for ABI compatibility, which is
> the target of my concerns. Now:
> * do you think we can elaborate more on this? For instance, same type of
> problem should apply to template parameters as well, exceptions, new
template parameters are not a major issue,
as you can just accept whatever the user gives
you. If you're explicitly instantiating the
template in the separately compiled library,
it should be safe to instantiate both versions,
and the one that isn't used will just be ignored.
It's probably okay to throw different exceptions
as the default assumption in C++ is that any function
can throw any exception.
A function that has the same mangled name in
different standards and is defined in multiple
translation units (i.e. inline functions or
function templates) must be identical regardless
of the standard. Note that to be strictly correct
it is not enough for the function to have the
same effective behavior, as the optimizer is
permitted to make assumptions based on the actual
implementation. Also note that this is the hardest
thing to get right and most code that tries to be
ABI compatible across multiple standards tends to
fudge it and hope for the best.
If a function takes different parameters depending
on the language standard, then it is a different
function and both versions can coexist.
> * do you think we can set up mechanisms that checks we are doing it
> right? (apart from trial and error, which has an exponential complexity
> in the number of types). I am just unaware of any tool or methodology
> that may help me doing it right.
Just build the library and test case with different
standards. If it works, it's probably good enough.
>> - The internal implementation can pick one or the
>> other. If you want ABI compatibility between C++03
>> and C++11, and the object crosses an ABI boundary,
>> that means always using boost::xxx.
> I was hoping for another solution ... To me, that means that long run,
> boost is implementing a side, non-compatible, C++ standard.
Pick your poison. It's impossible to use only std::xxx
in the ABI while still being link-compatible with C++03.
Personally, I can live with requiring a consistent std version,
in which case, this is not a problem.
>> For Boost.Test my overall recommendation is:
>> always use boost::function, but use std::bind
>> when it is available.
> The little story behind boost::bind was that, I believe around ~1.60, I
> encountered issues between std::bind and boost::function for moveable
> parameters. Maybe I was doing it wrong at that time, now it seems to be
> fixed (I tested). But I think the problem remains.
In the worst case, you can use
std::bind -> std::function -> boost::function.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk