[llvm] r186543 - Add an explicit operator bool conversion to DIDescriptor to make

Eric Christopher echristo at gmail.com
Wed Jul 17 17:29:11 PDT 2013


Good idea. Done :)

-eric

On Wed, Jul 17, 2013 at 4:01 PM, David Blaikie <dblaikie at gmail.com> wrote:
> On Wed, Jul 17, 2013 at 3:53 PM, Eric Christopher <echristo at gmail.com> wrote:
>> Author: echristo
>> Date: Wed Jul 17 17:53:05 2013
>> New Revision: 186543
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=186543&view=rev
>> Log:
>> Add an explicit operator bool conversion to DIDescriptor to make
>> it clear what we want to do. Unfortunately the conversion to
>> pointer operator fires now instead and chasing down all of the
>> conversions and making them explicit and handled is a large task
>> so add a FIXME with it.
>>
>> Modified:
>>     llvm/trunk/include/llvm/DebugInfo.h
>>
>> Modified: llvm/trunk/include/llvm/DebugInfo.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo.h?rev=186543&r1=186542&r2=186543&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/DebugInfo.h (original)
>> +++ llvm/trunk/include/llvm/DebugInfo.h Wed Jul 17 17:53:05 2013
>> @@ -102,6 +102,13 @@ namespace llvm {
>>      operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
>>      MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
>>
>> +    // An explicit operator bool so that we can do testing of DI values
>> +    // easily.
>> +    // FIXME: This operator bool isn't actually protecting anything at the
>> +    // moment due to the conversion operator above making DIDescriptor nodes
>> +    // implicitly convertable to pointer.
>
> In case it's not clear to the casual reader: DIDescriptor has always
> been boolean testable due to the presence of the pointer conversion
> above. This is a bit subtle, so we're adding a conversion to bool.
> It'd be nice if this was explicit (for the usual reasons that boolean
> conversion should be explicit because it's fraught with all sorts of
> weird cases where implicit bool could fire), and so it is marked as
> such - but then we just get the old behavior of boolean testing via
> the pointer conversion.
>
> I'd consider rephrasing the comment to:
>
> "... due to the pointer conversion operator above making DIDescriptor
> nodes implicitly convertible to bool."
>
>> +    LLVM_EXPLICIT operator bool() const { return DbgNode != 0; }
>> +
>>      unsigned getTag() const {
>>        return getUnsignedField(0) & ~LLVMDebugVersionMask;
>>      }
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list