summaryrefslogtreecommitdiff
path: root/compilerplugins/clang
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-11-06 13:33:29 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-11-06 15:18:15 +0100
commit0269fb72e886f0f04652fdadeaedf653f518ca61 (patch)
tree691e42a4f6df48352cdf0bd28da94841f8ebdc73 /compilerplugins/clang
parent2796d979fad388b32c466b8fb6d3dce8b5bdf31d (diff)
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.grandin@collabora.co.uk> Tested-by: Jenkins
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r--compilerplugins/clang/rangedforcopy.cxx37
-rw-r--r--compilerplugins/clang/test/rangedforcopy.cxx10
2 files changed, 31 insertions, 16 deletions
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: */