Skip to content

When compiling C, taking the address of an expression of type void, and warning about such #60243

Open
@pascal-cuoq

Description

@pascal-cuoq

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions