[PATCH] D71857: [NFC] Fixes -Wrange-loop-analysis warnings

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 4 11:38:41 PST 2020


MaskRay added a comment.

In D71857#1804307 <https://reviews.llvm.org/D71857#1804307>, @Mordante wrote:

> In D71857#1800663 <https://reviews.llvm.org/D71857#1800663>, @MaskRay wrote:
>
> > I think there is a false positive.
> >
> > https://github.com/llvm/llvm-project/tree/master/lld/ELF/Relocations.cpp#L1622
> >
> >   for (const std::pair<ThunkSection *, uint32_t> ts : isd->thunkSections)
> >   
>
>
> Removing the `const` like L1648 will also solve the issue.


Yes, both `std::pair` and `auto` work, but `const std::pair` doesn't. std::pair has an unfortunate user-defined copy assignment operator (https://eel.is/c++draft/pairs#pair-16 "Assigns p.first to first and p.second to second." Does this wording mandate a user-defined function?) I will drop `const` for this lld file.

For other user-defined types. I think loosening the diagnostic to allow trivially copyable types will be nice. Types that take only a few words (say. 1~3) are likely faster with a copy.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71857/new/

https://reviews.llvm.org/D71857





More information about the cfe-commits mailing list