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
This commit is contained in:
Noel Grandin
2024-11-06 15:18:15 +01:00
parent 2796d979fa
commit 0269fb72e8
2 changed files with 31 additions and 16 deletions
+21 -16
View File
@@ -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;
}
@@ -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: */