From 143b6442381dc7a667fc17c75dfc1d8c6c52fdfe Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Wed, 23 Sep 2015 18:40:47 +0000 Subject: Fix loop-convert for const references to containers. Previously we would use a non-const loop variable in the range-based loop for: void f(const std::vector &v) { for (size_t i = 0; i < v.size(); ++i) { Now we use const auto&. Note that we'll also want to use a copy at least for simple types. llvm-svn: 248418 --- clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp') diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp index 2c623727119..054e5ce94d9 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp @@ -391,6 +391,12 @@ static bool containerIsConst(const Expr *ContainerExpr, bool Dereference) { return false; CType = CType->getPointeeType(); } + // If VDec is a reference to a container, Dereference is false, + // but we still need to check the const-ness of the underlying container + // type. + if (const auto &RT = CType->getAs()) { + CType = RT->getPointeeType(); + } return CType.isConstQualified(); } return false; -- cgit v1.2.3