[llvm] r311948 - Remove an unnecessary const_cast.

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 18:31:13 PDT 2017



> On Aug 28, 2017, at 5:16 PM, David Blaikie <dblaikie at gmail.com> wrote:
> 
> Does this even need the variable then?

Yes. As the new comment says << takes a reference to a pointer -- we need an lvalue. 

> Maybe easier to read as:
> 
>   *Out << &OptDiagBase;
> 
> (& even drop the {} around the if (& while you're there, maybe roll the 'Out' into the if condition, if it's not used after the 'if'))
> 
>> On Mon, Aug 28, 2017 at 4:01 PM Adam Nemet via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>> Author: anemet
>> Date: Mon Aug 28 16:00:13 2017
>> New Revision: 311948
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=311948&view=rev
>> Log:
>> Remove an unnecessary const_cast.
>> 
>> I think that this is dating back to when emit used to take a const reference.
>> 
>> Modified:
>>     llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
>> 
>> Modified: llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp?rev=311948&r1=311947&r2=311948&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp (original)
>> +++ llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp Mon Aug 28 16:00:13 2017
>> @@ -165,7 +165,8 @@ void OptimizationRemarkEmitter::emit(
>> 
>>    yaml::Output *Out = F->getContext().getDiagnosticsOutputFile();
>>    if (Out) {
>> -    auto *P = const_cast<DiagnosticInfoOptimizationBase *>(&OptDiagBase);
>> +    // For remarks the << operator takes a reference to a pointer.
>> +    auto *P = &OptDiagBase;
>>      *Out << P;
>>    }
>>    // FIXME: now that IsVerbose is part of DI, filtering for this will be moved
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170828/364042f6/attachment.html>


More information about the llvm-commits mailing list