summaryrefslogtreecommitdiff
path: root/cppu
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-05-18 08:39:17 +0200
committerStephan Bergmann <sbergman@redhat.com>2022-05-18 09:30:41 +0200
commit9c3c6a6b661ea8f84c1285b07a502de5c98a1495 (patch)
tree80c0ae8b54b7df6326953e3bb2d607996a08242c /cppu
parentf8512cf3a8aabdba60c2994bed71c845efc6a25e (diff)
Replace OFFSET_OF macro with a function template
(in preparation of extending loplugin:redundantcast to more reinterpret_cast scenarios, which would have caused a false positive here). Required a tweak to loplugin:fakebool (as the relevant reinterpret_cast to silence some occurrences is no longer seen "inline" now), and the heuristics of loplugin:unused no longer worked (also because of the now-hidden reinterpret_cast'ing), but adding a maybe_unused attribute looks better than tweaking that plugin's heuristics even further. Change-Id: Iead1a9b31983918cf8f3b0e6c727c0081437c6d2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134504 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'cppu')
-rw-r--r--cppu/source/uno/check.cxx72
1 files changed, 37 insertions, 35 deletions
diff --git a/cppu/source/uno/check.cxx b/cppu/source/uno/check.cxx
index 2c289587c8a6..60ab3dba4e30 100644
--- a/cppu/source/uno/check.cxx
+++ b/cppu/source/uno/check.cxx
@@ -260,11 +260,13 @@ static_assert(sizeof(second) == sizeof(int), "sizeof(second) != sizeof(int)");
struct Char4
{
- Char3 chars;
+ [[maybe_unused]] Char3 chars;
char c;
};
-#define OFFSET_OF( s, m ) reinterpret_cast< size_t >(reinterpret_cast<char *>(&reinterpret_cast<s *>(16)->m) -16)
+template<typename T1, typename T2> std::size_t OFFSET_OF(T2 T1::* p) {
+ return reinterpret_cast< size_t >(reinterpret_cast<char *>(&(reinterpret_cast<T1 *>(16)->*p)) -16);
+}
class BinaryCompatible_Impl
{
@@ -273,48 +275,48 @@ public:
};
BinaryCompatible_Impl::BinaryCompatible_Impl()
{
- assert(OFFSET_OF(N, p) == 8);
+ assert(OFFSET_OF(&N::p) == 8);
- assert(OFFSET_OF(C2, n2) == 4);
+ assert(OFFSET_OF(&C2::n2) == 4);
#if SAL_TYPES_ALIGNMENT8 == 2
- assert(OFFSET_OF(C3, d3) == 6);
- assert(OFFSET_OF(C3, n3) == 14);
- assert(OFFSET_OF(C4, n4) == 18);
- assert(OFFSET_OF(C4, d4) == 22);
- assert(OFFSET_OF(C5, n5) == 30);
- assert(OFFSET_OF(C5, b5) == 38);
- assert(OFFSET_OF(C6, c6) == 2);
- assert(OFFSET_OF(C6, b6) == 42);
-
- assert(OFFSET_OF(O2, p2) == 16);
+ assert(OFFSET_OF(&C3::d3) == 6);
+ assert(OFFSET_OF(&C3::n3) == 14);
+ assert(OFFSET_OF(&C4::n4) == 18);
+ assert(OFFSET_OF(&C4::d4) == 22);
+ assert(OFFSET_OF(&C5::n5) == 30);
+ assert(OFFSET_OF(&C5::b5) == 38);
+ assert(OFFSET_OF(&C6::c6) == 2);
+ assert(OFFSET_OF(&C6::b6) == 42);
+
+ assert(OFFSET_OF(&O2::p2) == 16);
#elif SAL_TYPES_ALIGNMENT8 == 4
- assert(OFFSET_OF(C3, d3) == 8);
- assert(OFFSET_OF(C3, n3) == 16);
- assert(OFFSET_OF(C4, n4) == 20);
- assert(OFFSET_OF(C4, d4) == 24);
- assert(OFFSET_OF(C5, n5) == 32);
- assert(OFFSET_OF(C5, b5) == 40);
- assert(OFFSET_OF(C6, c6) == 4);
- assert(OFFSET_OF(C6, b6) == 48);
-
- assert(OFFSET_OF(O2, p2) == 20);
+ assert(OFFSET_OF(&C3::d3) == 8);
+ assert(OFFSET_OF(&C3::n3) == 16);
+ assert(OFFSET_OF(&C4::n4) == 20);
+ assert(OFFSET_OF(&C4::d4) == 24);
+ assert(OFFSET_OF(&C5::n5) == 32);
+ assert(OFFSET_OF(&C5::b5) == 40);
+ assert(OFFSET_OF(&C6::c6) == 4);
+ assert(OFFSET_OF(&C6::b6) == 48);
+
+ assert(OFFSET_OF(&O2::p2) == 20);
#elif SAL_TYPES_ALIGNMENT8 == 8
- assert(OFFSET_OF(C3, d3) == 8);
- assert(OFFSET_OF(C3, n3) == 16);
- assert(OFFSET_OF(C4, n4) == 24);
- assert(OFFSET_OF(C4, d4) == 32);
- assert(OFFSET_OF(C5, n5) == 40);
- assert(OFFSET_OF(C5, b5) == 48);
- assert(OFFSET_OF(C6, c6) == 8);
- assert(OFFSET_OF(C6, b6) == 64);
-
- assert(OFFSET_OF(O2, p2) == 24);
+ assert(OFFSET_OF(&C3::d3) == 8);
+ assert(OFFSET_OF(&C3::n3) == 16);
+ assert(OFFSET_OF(&C4::n4) == 24);
+ assert(OFFSET_OF(&C4::d4) == 32);
+ assert(OFFSET_OF(&C5::n5) == 40);
+ assert(OFFSET_OF(&C5::b5) == 48);
+ assert(OFFSET_OF(&C6::c6) == 8);
+ assert(OFFSET_OF(&C6::b6) == 64);
+
+ assert(OFFSET_OF(&O2::p2) == 24);
#else
# error unexpected alignment of 8 byte types
#endif
- assert(OFFSET_OF(Char4, c) == 3);
+ assert(OFFSET_OF(&Char4::c) == 3);
}
BinaryCompatible_Impl aTest;