Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does removing const from a function return type break ABI?

Tags:

c++

constants

abi

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.

like image 962
Petr Avatar asked May 31 '16 13:05

Petr


People also ask

What breaks ABI compatibility?

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.

What is ABI in c++?

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.


1 Answers

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.

like image 184
Smeeheey Avatar answered Oct 18 '22 20:10

Smeeheey