[llvm-dev] Is ArrayRef supposed to be immutable?

Daniel Berlin via llvm-dev llvm-dev at lists.llvm.org
Mon Oct 2 10:31:04 PDT 2017


On Mon, Oct 2, 2017 at 9:37 AM, Zachary Turner via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> It's possible I'm missing something, but I can't reproduce this:
>
>   std::vector<int> A = { 4, 15, 42 , 16, 8, 23};
>   ArrayRef<int> B(A);
>   std::sort(B.begin(), B.end());
>
> fails to compile for me.
>
>
As later mentioned, it was transient and appears to have only affected some
version  :)
Because of that, i stopped looking into it after tracking it down to what
appears to be a hilarious miscompile of clang.


> ArrayRef<T>::iterator is specified as `const T *`, so I'm not seeing how
> this could happen?
>
> On Sun, Oct 1, 2017 at 4:01 PM Chris Lattner via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> +1, totally a bug.  That’s the domain of MutableArrayRef.
>>
>> -Chris
>>
>> On Oct 1, 2017, at 6:52 AM, David Blaikie via llvm-dev <
>> llvm-dev at lists.llvm.org> wrote:
>>
>> +1 seems like a bug
>>
>> On Sun, Oct 1, 2017 at 12:35 AM Reid Kleckner via llvm-dev <
>> llvm-dev at lists.llvm.org> wrote:
>>
>>> It wraps a constant T* and a size_t, so I'm surprised std::sort works.
>>> It shouldn't.
>>>
>>> On Sep 30, 2017 5:22 PM, "Daniel Berlin via llvm-dev" <
>>> llvm-dev at lists.llvm.org> wrote:
>>>
>>> It seems like ArrayRefs are supposed to be immutable (
>>> However, as far as i can tell, the iterators are defined wrong to make
>>> this true.
>>>
>>> While
>>> ArrayRef<int> Foo(Something);
>>> Foo[0] = 5;
>>>
>>> will give a compile time error.
>>>
>>> something like:
>>>
>>> ArrayRef<int> Foo(Something);
>>> std::sort(Foo.begin(), Foo.end());
>>>
>>> Will work fine.
>>>
>>> Is this expected?
>>>
>>> (FWIW: I expected this to only work with a MutableArrayRef)
>>>
>>>
>>>
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> llvm-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>>
>>>
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> llvm-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171002/0bb0c926/attachment.html>


More information about the llvm-dev mailing list