compilerplugins/clang/fakebool.cxx      |    5 +-
 compilerplugins/clang/test/fakebool.cxx |   14 ++++++
 cppu/source/uno/check.cxx               |   72 ++++++++++++++++----------------
 3 files changed, 54 insertions(+), 37 deletions(-)

New commits:
commit 9c3c6a6b661ea8f84c1285b07a502de5c98a1495
Author:     Stephan Bergmann <[email protected]>
AuthorDate: Wed May 18 08:39:17 2022 +0200
Commit:     Stephan Bergmann <[email protected]>
CommitDate: Wed May 18 09:30:41 2022 +0200

    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 <[email protected]>

diff --git a/compilerplugins/clang/fakebool.cxx 
b/compilerplugins/clang/fakebool.cxx
index 80efa55bd432..cc7a9434a69e 100644
--- a/compilerplugins/clang/fakebool.cxx
+++ b/compilerplugins/clang/fakebool.cxx
@@ -451,9 +451,10 @@ bool FakeBool::VisitUnaryOperator(UnaryOperator * op) {
     Expr const * e1 = op->getSubExpr()->IgnoreParenCasts();
     if (isFakeBool(e1->getType()) != FBK_No) {
         if (DeclRefExpr const * e2 = dyn_cast<DeclRefExpr>(e1)) {
-            VarDecl const * d = dyn_cast<VarDecl>(e2->getDecl());
-            if (d != nullptr) {
+            if (auto const d = dyn_cast<VarDecl>(e2->getDecl())) {
                 varDecls_.erase(d);
+            } else if (auto const d = dyn_cast<FieldDecl>(e2->getDecl())) {
+                fieldDecls_.erase(d);
             }
         } else if (auto const e3 = dyn_cast<MemberExpr>(e1)) {
             if (auto const d = dyn_cast<FieldDecl>(e3->getMemberDecl())) {
diff --git a/compilerplugins/clang/test/fakebool.cxx 
b/compilerplugins/clang/test/fakebool.cxx
index 936e970e5e85..144bf4a28a15 100644
--- a/compilerplugins/clang/test/fakebool.cxx
+++ b/compilerplugins/clang/test/fakebool.cxx
@@ -33,4 +33,18 @@ struct S3 {
     void f() { S2 s(b_); }
 };
 
+namespace {
+
+struct S4 {
+    sal_Bool b;
+};
+
+}
+
+void f() {
+    sal_Bool b;
+    (void) &b;
+    (void) &S4::b;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
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;

Reply via email to