r175500 - Fix bug in LineState comparison function.

David Blaikie dblaikie at gmail.com
Tue Feb 19 09:36:22 PST 2013


On Tue, Feb 19, 2013 at 9:35 AM, David Blaikie <dblaikie at gmail.com> wrote:

>
>
>
> On Tue, Feb 19, 2013 at 1:28 AM, Daniel Jasper <djasper at google.com> wrote:
>
>> Author: djasper
>> Date: Tue Feb 19 03:28:55 2013
>> New Revision: 175500
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=175500&view=rev
>> Log:
>> Fix bug in LineState comparison function.
>>
>> The key bug was
>>
>>   if (Other.StartOfLineLevel < StartOfLineLevel) ..
>>
>> instead of
>>
>>   if (Other.StartOfLineLevel != StartOfLineLevel) ..
>>
>> Also cleaned up the function to be more consistent in the comparisons.
>>
>> Modified:
>>     cfe/trunk/lib/Format/Format.cpp
>>
>> Modified: cfe/trunk/lib/Format/Format.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=175500&r1=175499&r2=175500&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Format/Format.cpp (original)
>> +++ cfe/trunk/lib/Format/Format.cpp Tue Feb 19 03:28:55 2013
>> @@ -394,20 +394,20 @@ private:
>>
>>      /// \brief Comparison operator to be able to used \c LineState in \c
>> map.
>>      bool operator<(const LineState &Other) const {
>>
>
> I would've thought this whole thing would've been less error prone to
> write as:
>
> return a < x.a &&
>    b < x.b &&
>    ...
>
> is that not the case?
>

Nevermind, think it's too early on a Monday - pretty sure this makes no
sense...


>
>
>> -      if (Other.NextToken != NextToken)
>> -        return Other.NextToken > NextToken;
>> -      if (Other.Column != Column)
>> -        return Other.Column > Column;
>> -      if (Other.VariablePos != VariablePos)
>> -        return Other.VariablePos < VariablePos;
>> -      if (Other.LineContainsContinuedForLoopSection !=
>> -          LineContainsContinuedForLoopSection)
>> +      if (NextToken != Other.NextToken)
>> +        return NextToken < Other.NextToken;
>> +      if (Column != Other.Column)
>> +        return Column < Other.Column;
>> +      if (VariablePos != Other.VariablePos)
>> +        return VariablePos < Other.VariablePos;
>> +      if (LineContainsContinuedForLoopSection !=
>> +          Other.LineContainsContinuedForLoopSection)
>>          return LineContainsContinuedForLoopSection;
>> -      if (Other.ParenLevel != ParenLevel)
>> -        return Other.ParenLevel < ParenLevel;
>> -      if (Other.StartOfLineLevel < StartOfLineLevel)
>> -        return Other.StartOfLineLevel < StartOfLineLevel;
>> -      return Other.Stack < Stack;
>> +      if (ParenLevel != Other.ParenLevel)
>> +        return ParenLevel < Other.ParenLevel;
>> +      if (StartOfLineLevel != Other.StartOfLineLevel)
>> +        return StartOfLineLevel < Other.StartOfLineLevel;
>> +      return Stack < Other.Stack;
>>      }
>>    };
>>
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130219/3fbc2d57/attachment.html>


More information about the cfe-commits mailing list