compilerplugins/clang/rangedforcopy.cxx | 10 ++++++++++ compilerplugins/clang/test/rangedforcopy.cxx | 10 ++++++++++ 2 files changed, 20 insertions(+)
New commits: commit cd3f8acc4dc803fef4453ae31037eba15acfefa7 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Thu May 4 15:33:00 2023 +0200 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Thu May 4 19:09:55 2023 +0200 Adapt loplugin:randedforcopy to libc++ std::vector<bool> Seen unhelpful > sc/source/core/data/dpoutput.cxx:882:10: error: Loop variable passed by value, pass by reference instead, e.g. 'const const reference&' [loplugin:rangedforcopy] > for (const auto bCompact: aRowCompactFlags) > ^~~~~~~~~~~~~~~~~~~~ on macOS Change-Id: I9854e2498950951efc640bf31741229631e00e87 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151393 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/compilerplugins/clang/rangedforcopy.cxx b/compilerplugins/clang/rangedforcopy.cxx index b0ab6bf35027..2de4766dab04 100644 --- a/compilerplugins/clang/rangedforcopy.cxx +++ b/compilerplugins/clang/rangedforcopy.cxx @@ -12,6 +12,7 @@ #include <string> #include <iostream> +#include "check.hxx" #include "plugin.hxx" #include "clang/AST/CXXInheritance.h" @@ -54,6 +55,15 @@ bool RangedForCopy::VisitCXXForRangeStmt( const CXXForRangeStmt* stmt ) const QualType type = varDecl->getType(); if (type->isRecordType() && !type->isReferenceType() && !type->isPointerType()) { + 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, diff --git a/compilerplugins/clang/test/rangedforcopy.cxx b/compilerplugins/clang/test/rangedforcopy.cxx index f4346b18111d..e9a836e2489c 100644 --- a/compilerplugins/clang/test/rangedforcopy.cxx +++ b/compilerplugins/clang/test/rangedforcopy.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <vector> + struct S { int i1; @@ -27,4 +29,12 @@ void f(S const (&a)[2]) } } +void f(std::vector<bool> const& v) +{ + for (auto b : v) + { + (void)b; + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */