Open
Description
The following C program, when compiled with Clang 15 with -pedantic
, causes the following warnings.
void *p;
void *g(void) {
return &(p[0]);
}
The warnings:
<source>:4:13: warning: subscript of a pointer to void is a GNU extension [-Wgnu-pointer-arith]
return &(p[0]);
~^
<source>:4:10: warning: ISO C forbids taking the address of an expression of type 'void' [-Wpedantic]
return &(p[0]);
^ ~~~~
The second warning says, without a clause number, that ISO C forbids taking the address of an expression of type void
. If this is true, then Clang should reject the following C program when -pedantic -pedantic-errors -std=c17
are set:
void *p;
void *g(void) {
return &(*p);
}
In this case Clang 15 compiles without warning.
I don't think that ISO C forbids taking the address of an expression of type 'void' (and if I'm right, this Clang warning should not exist). But if ISO C does forbid taking the address of an expression of type 'void', then the second example should result in a warning when compiled with -pedantic -pedantic-errors -std=c17
.