[PATCH] D75285: Mark restrict pointer or reference to const as invariant

Jon Chesterfield via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 28 02:08:57 PST 2020


JonChesterfield added a comment.

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.


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

https://reviews.llvm.org/D75285





More information about the cfe-commits mailing list