1

Say that you create a library with a class MyClass that has proper move assignment operators and move constructors. Furthermore, this library has properly defined and implemented MyClass MyClass::operator + (const MyClass& other). This class is compiled with -std=c++11 in order for these operators and syntax like MyClass&& to make sense.

If you later have a program not compiled with -std=c++11 using this library and creating instances of the class MyClass, will you be able to take advantage of move semantics?

That, is will the following call the move constructor of MyClass?

MyClass first, second;
// initialize first and second
MyClass moved = first + second; // hopefully uses move semantics

I know that this code could not create its own class and use syntax like MyClass&& without having compilation errors, but hopefully it would still be able to take advantage of C++11 by using the C++11 library...

Thanks for any clarification.

NoseKnowsAll
  • 4,593
  • 2
  • 23
  • 44
  • 7
    I suspect you won't be able to compile your program since it won't recognize the C++11 syntax contained in the library headers. – Anon Mail Oct 20 '15 at 22:13

2 Answers2

3

The ABI of C++03 and C++11 doesn't differ, so object files aren't a problem. Your library can use C++11 internally as much as you want, but headers with C++11 syntax can't be used for C++03 projects, the compiler throws errors.

Youka
  • 2,646
  • 21
  • 33
  • 1
    C++ doesn't specify an ABI and compilers can change the ABI whenever they feel like it. – nwp Oct 20 '15 at 22:30
  • 1
    I guess you mean in GCC? – juanchopanza Oct 20 '15 at 22:30
  • They can do, but realistically, they can't do, at least on Linux. The breakage would be severe. – Puppy Oct 20 '15 at 22:31
  • Well if your compiler is fully compliant they will most likely differ. One example is `std::list` that in C++11 become bigger by one `size_t`, and `std::string` with `libstdc++`. Those are not standard compliant in the libstdc++, unless you use the new abi (that is obviously not backward compatible). I posted a similar question (http://stackoverflow.com/questions/10014042/libary-compatibility-between-c11-and-c03), and the accepted answer is basically "no". – sbabbi Oct 20 '15 at 22:56
2

The library's separately compiled internal implementation details may make use of move semantics. The header and the caller may make no use of move semantics, since they're not supported.

Puppy
  • 144,682
  • 38
  • 256
  • 465