clang-tidy-10 as of 2020-01-31 gives the following false positive ====== test.cpp ====== template<typename RANGE> void f(RANGE r) { for (char c : r) { } } ====================== $ clang-tidy test.cpp --checks='cppcoreguidelines*' test.cpp:3:13: warning: variable 'c' is not initialized [cppcoreguidelines-init-variables] for (char c : r) { ^ = 0 Also reproducible on trunk: https://godbolt.org/z/s_bCSi
This is an odd case, for some reason this code doesn't trigger the warning ========================== template <typename T> void g(std::vector<T> r) { for (T c : r) { } } ========================== https://godbolt.org/z/L9NdQx Anyway here is a fix, just disable the check when we detect the var decl is the loop variable of a for range statement. https://reviews.llvm.org/D73843
Fixed in https://github.com/llvm/llvm-project/commit/efcd09cea9a51c522954aa24e4b5513266daf6c3
Thank you. I have verified that this solves my original problem. Will this be cherry-picked to the 10.x branch?
I'll add it as a release blocker but I'm not entirely sure it should go in there. I'll let Hans have the final verdict on this matter
(In reply to Nathan James from comment #4) > I'll add it as a release blocker but I'm not entirely sure it should go in > there. I'll let Hans have the final verdict on this matter Sounds good to me. Cherry-picked as 84cda4cceabdfec4f130bfafe7bbd050aa65b2ec