15

I have the following scenario:

There are two components one is written in C++11 the other in C++98. Both are compiled from scratch using the same GCC 4.9. One uses the implicit default --std=gnu++98 the other explicitly sets --std=c++11.

Even after doing some research I could not completely answer the question if this could cause issues.

The GCC wiki says:

The C++98 language is ABI-compatible with the C++11 language, but several places in the library break compatibility. This makes it dangerous to link C++98 objects with C++11 objects. If you can recompile your code in matching versions of the language, you should do that.

This suggest that problems are to be expected.

So the questions are:

  1. Are there issues if the two components built with --std=gnu++98 and --std=c++11 are linked together, even tough they use same libstdc++ and are built with the same compiler (GCC 4.9)?

  2. Does Dual ABI support form GCC 5.1 have an influence in that case?

Pascal
  • 423
  • 4
  • 13
  • I'd suggest just building both with `-std=c++11` (or the GNU dialect). – Jesper Juhl Jun 27 '16 at 14:46
  • 1
    That would be ideal, but in this case the compilation of the first component fails to compile when built with something newer then C++98 and changing it is not possible right now. – Pascal Jun 27 '16 at 14:50
  • 1
    `std::string` used? Second, those breaking changes, maybe you should be scared about them: many of the "breaks" might be actual bugs. – Yakk - Adam Nevraumont Jun 27 '16 at 15:56
  • `std::string` is used at the interface between the two. What do you mean by actual bugs? – Pascal Jun 27 '16 at 19:57

1 Answers1

2

1) There may be issues since, for example, the implementation of some part of the lib you mentioned changed.

2) Yes.

I would recompile everything in one of the two c++ version. If that is not an option (third party library etc.) using the dual ABI mechanism could be a solution. Be very careful on what it's shared between different version of the code.

The part of the wiki you mentioned talks about situations where, for example, old code tries to do stuff that is no longer supported (different semantic but same syntax).

Robbykk
  • 66
  • 6
  • Regarding answer 1) Do you mean the issue is that the interface of `libstdc++` changed between C++98 and C++11 changed. Or is it just that they might behave slightly different and bugs could arise because of that? In the second case this should not happen if the code is correct according to the C++ standard right? – Pascal Jun 27 '16 at 19:56
  • Both. Since you use GCC 4.9 you may not experience any problem of that kind (you will use the old implementation of libstdc++), what you have to be careful are other different libraries for which you don't know the dependencies. In libstdc++ you are lucky because the changes are inlined with the namespace and the linker would warn you if there were problems of this kind. This may or may not happen with other libraries (for example boost presents an high risk of being a pain in this kind of situation). – Robbykk Jun 28 '16 at 13:11