Skip to content

Commit 8d5df91

Browse files
committed
Support [[msvc::no_unique_address]] with cl.
* [[no_unique_address]] with cl is silently ignored. * Don't use either with with clang-cl, they are unrecognised. Useful links: * https://reviews.llvm.org/D110485 * llvm/llvm-project#49358
1 parent d1b62d5 commit 8d5df91

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

include/tuplet/tuple.hpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
#include <type_traits>
77
#include <utility>
88

9+
#if (__has_cpp_attribute(no_unique_address))
10+
#define TUPLET_NO_UNIQUE_ADDRESS [[no_unique_address]]
11+
#elif (__has_cpp_attribute(msvc::no_unique_address)) \
12+
|| ((defined _MSC_VER) && (!defined __clang__))
13+
// Note __has_cpp_attribute(msvc::no_unique_address) itself doesn't work as
14+
// of 19.30.30709, even though the attribute itself is supported. See
15+
// https://github.com/llvm/llvm-project/issues/49358#issuecomment-981041089
16+
#define TUPLET_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
17+
#else
18+
// no_unique_address is not available.
19+
#define TUPLET_NO_UNIQUE_ADDRESS
20+
#endif
21+
922
// tuplet concepts and traits
1023
namespace tuplet {
1124
template <class T>
@@ -94,7 +107,7 @@ struct tuple_elem {
94107
static T decl_elem(tag<I>);
95108
using type = T;
96109

97-
[[no_unique_address]] T value;
110+
TUPLET_NO_UNIQUE_ADDRESS T value;
98111

99112
constexpr decltype(auto) operator[](tag<I>) & { return (value); }
100113
constexpr decltype(auto) operator[](tag<I>) const& { return (value); }
@@ -242,8 +255,8 @@ namespace tuplet {
242255
template <class First, class Second>
243256
struct pair {
244257
constexpr static size_t N = 2;
245-
[[no_unique_address]] First first;
246-
[[no_unique_address]] Second second;
258+
TUPLET_NO_UNIQUE_ADDRESS First first;
259+
TUPLET_NO_UNIQUE_ADDRESS Second second;
247260

248261
constexpr decltype(auto) operator[](tag<0>) & { return (first); }
249262
constexpr decltype(auto) operator[](tag<0>) const& { return (first); }

0 commit comments

Comments
 (0)