diff options
Diffstat (limited to 'compilerplugins/clang/rangedforcopy.cxx')
-rw-r--r-- | compilerplugins/clang/rangedforcopy.cxx | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/compilerplugins/clang/rangedforcopy.cxx b/compilerplugins/clang/rangedforcopy.cxx index 68004a1708ae..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" @@ -45,15 +46,29 @@ bool RangedForCopy::VisitCXXForRangeStmt( const CXXForRangeStmt* stmt ) const VarDecl* varDecl = stmt->getLoopVariable(); if (!varDecl) return true; + if (isa<DecompositionDecl>(varDecl)) + { + // Assume that use of a non-reference structured binding is intentional: + return true; + } 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, "Loop variable passed by value, pass by reference instead, e.g. 'const %0&'", - compat::getBeginLoc(varDecl)) + varDecl->getBeginLoc()) << name << varDecl->getSourceRange(); } |