[libcxx-commits] [PATCH] D100429: [libc++][ranges] Add range.cmp: equal_to, not_equal_to, less, etc.
Arthur O'Dwyer via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Apr 21 10:10:35 PDT 2021
Quuxplusone added inline comments.
================
Comment at: libcxx/test/support/pointer_comparison_test_helper.h:25-28
+ int* a = &buff[0];
+ int* b = &buff[1];
+ int* end = buff + 2;
+ int* pointers[4] = {a, b, nullptr, end};
----------------
I don't mind the loop now; but please use the values I gave:
```
struct {
int a, b;
} local;
int *pointers[] = { &local.a, &local.b, nullptr, &local.a + 1 };
```
The reason for these four values in particular is:
- `&a < &b` is true in practice but unspecified in theory (AFAIK) (because `a` and `b` are not members of the same array).
- `&a < &a+1` is true in both practice and theory
- `&b == &a+1` is UB in practice but unspecified in theory
(`&b` and `&a+1` are the same memory address in practice; but compilers including GCC and perhaps Clang will do front-end optimizations under the assumption that a pointer derived from `a` cannot possibly alias a pointer derived from `b`. So in practice you get inconsistent results; see my blog post linked earlier. //But//, for our purposes here, as @tcanens said, this is the sole really interesting case. Certainly it is uninteresting to compare `&buff[0]` with `&buff[1]`.)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100429/new/
https://reviews.llvm.org/D100429
More information about the libcxx-commits
mailing list