compilerplugins/clang/rangedforcopy.cxx      |   37 +++++++++++++++------------
 compilerplugins/clang/test/rangedforcopy.cxx |   10 +++++++
 2 files changed, 31 insertions(+), 16 deletions(-)

New commits:
commit 0269fb72e886f0f04652fdadeaedf653f518ca61
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Nov 6 13:33:29 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Nov 6 15:18:15 2024 +0100

    ignore TypedWhichId in loplugin:rangedforcopy
    
    where using a "&" in a for loop is overkill
    
    Change-Id: Ic0d14f6d19c50b49cf7ce3bf2166d546a4d2685b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176130
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/compilerplugins/clang/rangedforcopy.cxx 
b/compilerplugins/clang/rangedforcopy.cxx
index 2de4766dab04..7ca859cc3904 100644
--- a/compilerplugins/clang/rangedforcopy.cxx
+++ b/compilerplugins/clang/rangedforcopy.cxx
@@ -53,25 +53,30 @@ bool RangedForCopy::VisitCXXForRangeStmt( const 
CXXForRangeStmt* stmt )
     }
 
     const QualType type = varDecl->getType();
-    if (type->isRecordType() && !type->isReferenceType() && 
!type->isPointerType())
+    if (!type->isRecordType() || type->isReferenceType() || 
type->isPointerType())
+        return true;
+
+    if 
(loplugin::TypeCheck(type).Class("__bit_const_reference").StdNamespace())
     {
-        if 
(loplugin::TypeCheck(type).Class("__bit_const_reference").StdNamespace())
-        {
-            // With libc++ without 
_LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL,
-            // iterating over a const std::vector<bool> non-compliantly uses a 
variable of some
-            // internal __bit_const_reference class type, rather than of type 
bool (see
-            // <https://reviews.llvm.org/D123851> "[libc++] Change
-            // vector<bool>::const_iterator::reference to bool in ABIv2"):
-            return true;
-        }
-        std::string name = type.getAsString();
-        report(
-               DiagnosticsEngine::Warning,
-               "Loop variable passed by value, pass by reference instead, e.g. 
'const %0&'",
-               varDecl->getBeginLoc())
-               << name << varDecl->getSourceRange();
+        // With libc++ without 
_LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL,
+        // iterating over a const std::vector<bool> non-compliantly uses a 
variable of some
+        // internal __bit_const_reference class type, rather than of type bool 
(see
+        // <https://reviews.llvm.org/D123851> "[libc++] Change
+        // vector<bool>::const_iterator::reference to bool in ABIv2"):
+        return true;
     }
 
+    // trivial class, ignore it
+    if (loplugin::TypeCheck(type).Class("TypedWhichId").GlobalNamespace())
+        return true;
+
+    std::string name = type.getAsString();
+    report(
+           DiagnosticsEngine::Warning,
+           "Loop variable passed by value, pass by reference instead, e.g. 
'const %0&'",
+           varDecl->getBeginLoc())
+           << name << varDecl->getSourceRange();
+
     return true;
 }
 
diff --git a/compilerplugins/clang/test/rangedforcopy.cxx 
b/compilerplugins/clang/test/rangedforcopy.cxx
index e9a836e2489c..d83090d0a1d1 100644
--- a/compilerplugins/clang/test/rangedforcopy.cxx
+++ b/compilerplugins/clang/test/rangedforcopy.cxx
@@ -8,6 +8,7 @@
  */
 
 #include <vector>
+#include <svl/typedwhich.hxx>
 
 struct S
 {
@@ -37,4 +38,13 @@ void f(std::vector<bool> const& v)
     }
 }
 
+// no warning expected
+class SvxFontItem;
+constexpr TypedWhichId<SvxFontItem> EE_CHAR_FONTINFO1(12);
+constexpr TypedWhichId<SvxFontItem> EE_CHAR_FONTINFO2(13);
+void f2()
+{
+    for (auto nWhich : { EE_CHAR_FONTINFO1, EE_CHAR_FONTINFO2 })
+        (void)nWhich;
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to