[llvm] r220231 - Add const version of OwningBinary::getBinary

Lang Hames lhames at gmail.com
Thu Oct 30 11:54:20 PDT 2014


Hi Alexey,

This signature for getPtr looks odd:

static Binary *getPtr(const OwningBinary &Bin) {
  return Bin.getBinary().get();
}

I don't think this method should be able to extract a non-constant Binary*
from a constant OwningBinary. I think it should be:

static const Binary *getPtr(const OwningBinary &Bin) {
  return Bin.getBinary().get();
}

Right? (Either that, or getPtr should take a non-constant OwningBinary).

Cheers,
Lang.

On Mon, Oct 20, 2014 at 3:22 PM, Alexey Samsonov <vonosmas at gmail.com> wrote:

>
> On Mon, Oct 20, 2014 at 1:48 PM, David Blaikie <dblaikie at gmail.com> wrote:
>
>>
>>
>> On Mon, Oct 20, 2014 at 1:32 PM, Alexey Samsonov <vonosmas at gmail.com>
>> wrote:
>>
>>> Author: samsonov
>>> Date: Mon Oct 20 15:32:47 2014
>>> New Revision: 220231
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=220231&view=rev
>>> Log:
>>> Add const version of OwningBinary::getBinary
>>>
>>> Modified:
>>>     llvm/trunk/include/llvm/Object/Binary.h
>>>
>>> Modified: llvm/trunk/include/llvm/Object/Binary.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Binary.h?rev=220231&r1=220230&r2=220231&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/include/llvm/Object/Binary.h (original)
>>> +++ llvm/trunk/include/llvm/Object/Binary.h Mon Oct 20 15:32:47 2014
>>> @@ -140,6 +140,7 @@ public:
>>>    OwningBinary<T> &operator=(OwningBinary<T> &&Other);
>>>
>>>    std::unique_ptr<T> &getBinary();
>>> +  const std::unique_ptr<T> &getBinary() const;
>>>    std::unique_ptr<MemoryBuffer> &getBuffer();
>>>  };
>>>
>>> @@ -165,6 +166,11 @@ template <typename T> std::unique_ptr<T>
>>>    return Bin;
>>>  }
>>>
>>> +template <typename T>
>>> +const std::unique_ptr<T> &OwningBinary<T>::getBinary() const {
>>>
>>
>> Slightly curious thing to have a const version of, though it's probably
>> the best thing for symmetry (since ownership can't be transferred, it could
>> just return T* or, if it's always non-null, a T& - but it'd be weirdly
>> asymmetric). What's it for?
>>
>
> In a new code, I wanted to fetch raw Binary* from OwningBinary<Binary>
> (because I wanted to retain ownership in a callee). The straightfoward way
> to do this was:
>
> static Binary *getPtr(const OwningBinary &Bin) {
>   return Bin.getBinary().get();
> }
>
> OwningBinary OB = ....; // create owningBinary
> // store OB somewhere
> return getPtr(OB);
>
> but the code fails to compile because of the missing overload I added here.
>
>
>
>>
>>> +  return Bin;
>>> +}
>>> +
>>>  template <typename T>
>>>  std::unique_ptr<MemoryBuffer> &OwningBinary<T>::getBuffer() {
>>>    return Buf;
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>
>>
>>
>
>
> --
> Alexey Samsonov
> vonosmas at gmail.com
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141030/f100d5f3/attachment.html>


More information about the llvm-commits mailing list