rjmccall added a comment.

In D75285#1897537 <https://reviews.llvm.org/D75285#1897537>, @JonChesterfield 
wrote:

> In D75285#1897247 <https://reviews.llvm.org/D75285#1897247>, @yaxunl wrote:
>
> > If users derive a non-const pointer from the const pointer and modify it, 
> > doesn't that result in UB? Thanks.
>
>
> No. Modifying a const object is UB, so e.g. we can segv if it's in .rodata, 
> but a const pointer is not necessarily a pointer to a const object. If it's a 
> const pointer to a non-const object then one can cast it directly to a 
> non-const pointer and mutate at will.
>
> This unfortunately makes 'const int*' of rather less use than it would 
> otherwise be.


Right.  Note that this UB extends to all `const` objects, even locals, which is 
something that I don't think we currently have a good way to take advantage of 
in LLVM.

Unfortunately, this probably doesn't help Yaxun's use case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75285/new/

https://reviews.llvm.org/D75285



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to