Assume I have a library that declares a function returning const
type:
class Foo { ... };
const Foo makeFoo();
Now I want to remove const
from makeFoo()
return type (See my previous question). I can remove const
both from the header and the cpp file, rebuild the library, and link my code to the new library. However, I also have old code that is dynamically linked to this library, and I want it to continue to work with the new version of the library.
So, first question, does removing const
from return type break ABI?
Second question, the actual code is quite different: it is a template class that has a static member function and that is later explicitly instantiated:
// fooMaker.h
template<class Foo>
class FooMaker {
public:
static const Foo make();
};
// fooMaker.cpp
template<class Foo>
const Foo FooMaker<Foo>::make() { ... }
template class FooMaker<Foo1>;
template class FooMaker<Foo2>;
Is it changing anything?
If that's important, I'm using g++ under linux.
ABI break happens when one binary, e.g. shared object, uses a different ABI when calling functions on another shared object. If both binaries are not ABI compatible, the interpretation of the bytes would be wrong.
As C++ evolved over the years, the Application Binary Interface (ABI) used by a compiler often needed changes to support new or evolving language features. Consequently, programmers were expected to recompile all their binaries with every new compiler release.
The following guidelines on what affects the ABI suggest that the answer is yes, it does break ABI compatibility:
You cannot
...
For existing functions of any type:
- changing the return type in any way
Since you are changing the return type from const Foo
to Foo
I would say this falls foul.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With