https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61502
--- Comment #39 from Alexander Cherepanov <ch3root at openwall dot com> ---
For diversity, a couple of examples with zero sized objects. Even though they
don't have pointer arithmetic at all they could be classified as being about
past-the-end pointers:-) Please let me know if it's better to move them into a
separate bug (or bugs).
----------------------------------------------------------------------
#include <stdio.h>
int main()
{
struct {} x, y, *p = &x, *q = &y;
printf("eq1: %d\n", &x == &y);
printf("eq2: %d\n", p == q);
}
----------------------------------------------------------------------
$ gcc -std=c11 -Wall -Wextra test.c && ./a.out
eq1: 0
eq2: 1
----------------------------------------------------------------------
gcc x86-64 version: gcc (GCC) 10.0.0 20200110 (experimental)
----------------------------------------------------------------------
Empty structs is a gcc extension (they are UB according to C11, 6.7.2.1p8) but
IMHO the demonstrated instability is not good.
Happens only without optimizations (optimizations add some padding between `x`
and `y`).
Similar clang bug -- https://bugs.llvm.org/show_bug.cgi?id=44508.