Skip to content

Commit a21f2b7

Browse files
committed
Added macro for ABI compatibility
1 parent 47ccff3 commit a21f2b7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,12 @@ The follownig limitations are features that were not implemented simply because
7272

7373
## Notes
7474

75+
76+
### Alternative implementation
77+
7578
An alternative implementation of an "observable unique pointer" can be found [here](https://www.codeproject.com/articles/1011134/smart-observers-to-use-with-unique-ptr). It does not compile out of the box with gcc unfortunately, but it does contain more features (like creating an observer pointer from a raw `this`). Have a look to check if this better suits your needs.
79+
80+
81+
### ABI compatibility
82+
83+
When compiled in C++20 mode, by default the implementation will attempt to optimize empty deleters. This is not ABI-compatible with previous versions of C++, which lack the `[[no_unique_address]]` attribute (introduced in C++20). If ABI compatibility with previous versions of C++ is a concern to you, please define the macro `OUP_CPP17_ABI_COMPAT` before including the header of this library. This will disable the empty deleter optimisation, and enable binary compatibility with older C++ versions.

include/oup/observable_unique_ptr.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
#include <cstddef>
66
#include <utility>
77

8+
// When compiled in C++20 mode, by default the implementation will
9+
// attempt to optimize away empty deleters. This is not ABI-compatible
10+
// with previous versions of C++, which lack the [[no_unique_address]]
11+
// attribute. If ABI compatibility with previous versions of C++ is a
12+
// concern to you, please define the macro below.
13+
#if !defined(OUP_CPP17_ABI_COMPAT)
14+
# define OUP_CPP17_ABI_COMPAT
15+
#endif
16+
817
namespace oup {
918

1019
template<typename T>
@@ -61,7 +70,7 @@ class observable_unique_ptr {
6170
control_block* block = nullptr;
6271
T* data = nullptr;
6372

64-
#if __cplusplus == 202002L
73+
#if __cplusplus == 202002L && !defined(OUP_CPP17_ABI_COMPAT)
6574
[[no_unique_address]] Deleter deleter;
6675
#else
6776
Deleter deleter;

0 commit comments

Comments
 (0)