Details
- Reviewers
ldionne • Quuxplusone Mordante - Group Reviewers
Restricted Project - Commits
- rG01df675191de: [libc++] Enable modernize-loop-convert
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libcxx/include/locale | ||
---|---|---|
3224–3226 | IMO we don't want to do this.
|
libcxx/include/locale | ||
---|---|---|
3224–3226 | My first thought when I saw this was: Where does that magic 4 come from? |
LGTM!
libcxx/include/locale | ||
---|---|---|
3224–3226 |
|
libcxx/include/locale | ||
---|---|---|
3224–3226 | Drive-by comment: I did a quick check using a simple regex for \([^:]*$ (basically, strings that match for ( but don't contain the : character) and it didn't take long to find a case where it seems like clang-tidy should recommend using a range-based for loop. See include/__random/piecewise_linear_distribution.h: size_t __n = __x.__p_.__b_.size(); // ... for (size_t __i = 0; __i < __n; ++__i) __os << __sp << __x.__p_.__b_[__i]; If I'm reading this correctly, __b_ is a vector and it seems like a straightforward case for turning this into a range-based for loop, unless I'm missing something. So I'm a little concerned about why clang-tidy doesn't flag this. |
libcxx/include/locale | ||
---|---|---|
3224–3226 | In this case __n is used in other places as well. The line in your ellipse is __os << __n. I think clang-tidy only flags cases where there is no other use than indexing into some range. It's usually very conservative with regards to these kinds of usages. These checks are made to automagically modernize your code base, which wouldn't work if it weren't 100% sure that the fix-it applied is correct. |
libcxx/include/locale | ||
---|---|---|
3224–3226 | Interesting, thanks for the explanation. I don't see what issue could arise from keeping the __n variable while reducing the number of its usages, but I can see how it could be a limitation of the tool. |
libcxx/include/locale | ||
---|---|---|
3224–3226 | In this case I don't have a good answer. There are a lot of indirections until vector::begin returns a __wrap_iter<_Tp*>. IIUC it could technically be the case that vector::begin SFINAEs away with a non-default allocator. Do you think it would be worth filing a bug against clang-tidy for that? |
libcxx/include/locale | ||
---|---|---|
3224–3226 | If it's not too hard, then yes, it would be awesome to file a bug. Maybe there's some limitation that I'm not aware of, in which case I'd like to know about it, but as a user, I would definitely expect vector to be well-supported. |
I'm fine with this change for the sole reason that I find the diff after easier to read, too.
I'm fine with enabling the clang-tidy check as a "fly-by", however as @Quuxplusone said, if clang-tidy ever starts complaining about stuff and suggesting changes that we don't think are improvements, we'll want to disable those checks. In other words, I'm fine with this change since I think it *is* an improvement, but I want to make it clear that we're not blindly following what the tool tells us.
I agree with others that clang-tidy is probably missing a bunch of places where this can be applied, however we can tackle them as they come, and I guess I find it reassuring that clang-tidy is on the more conservative side.
IMO we don't want to do this.