https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119481
Bug ID: 119481 Summary: -fplan9-extensions violates the C standard (6.3.3.3p7) Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: alx at kernel dot org Target Milestone: --- <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3467.pdf#subsubsection.0.6.3.3.3> ``` alx@devuan:~/tmp$ cat cast.c | grep -Tn ^ 1: #include <stdio.h> 2: 3: struct B { 4: int i; 5: }; 6: struct A { 7: int j; 8: struct B; 9: }; 10: 11: int 12: main(void) 13: { 14: struct A a; 15: struct B *b; 16: int x; 17: 18: b = (struct B *) &a; 19: x = (&a == (struct A *) b); 20: 21: printf("%d\n", x); 22: 23: b = &a; 24: x = (&a == (struct A *) b); 25: 26: printf("%d\n", x); 27: } alx@devuan:~/tmp$ gcc -Wall -Wextra -fplan9-extensions cast.c alx@devuan:~/tmp$ ./a.out 1 0 ``` While some Plan9 extensions are interesting, there should be a diagnostic when an implicit conversion adds an offset to a pointer. The referenced paragraph from ISO C23 that is violated by this extension says: ``` A pointer to an object type can be converted to a pointer to a different object type. [...] when converted back again, the result shall compare equal to the original pointer. ```