[llvm] r272519 - Use 'auto' to avoid implicit copies.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 13 12:10:37 PDT 2016


Haven't checked if -Wrange-loop-analysis catches this. There was a
plan to turn that on by default in LLVM. Don't know what happened to
that.

On Mon, Jun 13, 2016 at 5:30 PM, David Blaikie <dblaikie at gmail.com> wrote:
> Hmm - I thought we had an actual warning for this? Am I remembering
> correctly? Could we turn it on for LLVM's build?
>
> On Sun, Jun 12, 2016 at 12:02 PM, Benjamin Kramer via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>>
>> Author: d0k
>> Date: Sun Jun 12 14:02:34 2016
>> New Revision: 272519
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=272519&view=rev
>> Log:
>> Use 'auto' to avoid implicit copies.
>>
>> td_type is std::pair<std::string, std::string>, but the map returns
>> elements of std::pair<const std::string, std::string>. In well-designed
>> languages like C++ that yields an implicit copy perfectly hidden by
>> constref's lifetime extension. Just use auto, the typedef obscured the
>> real type anyways.
>>
>> Found with a little help from clang-tidy's
>> performance-implicit-cast-in-loop.
>>
>> Modified:
>>     llvm/trunk/lib/IR/Attributes.cpp
>>
>> Modified: llvm/trunk/lib/IR/Attributes.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=272519&r1=272518&r2=272519&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/IR/Attributes.cpp (original)
>> +++ llvm/trunk/lib/IR/Attributes.cpp Sun Jun 12 14:02:34 2016
>> @@ -792,7 +792,7 @@ AttributeSet AttributeSet::get(LLVMConte
>>    }
>>
>>    // Add target-dependent (string) attributes.
>> -  for (const AttrBuilder::td_type &TDA : B.td_attrs())
>> +  for (const auto &TDA : B.td_attrs())
>>      Attrs.push_back(
>>          std::make_pair(Index, Attribute::get(C, TDA.first, TDA.second)));
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>


More information about the llvm-commits mailing list