Skip to content

-Wnull-pointer-arithmetic and -Wno-gnu #54444

Closed
@nickdesaulniers

Description

@nickdesaulniers

The following code w/ ToT LLVM (clang-15) produces the following warnings:

void *x(void) {
    return (char*)0 + 42;
}

void *y(void) {
    return (void*)0 + 42;
}
<source>:2:21: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
    return (char*)0 + 42;
           ~~~~~~~~ ^
<source>:6:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
    return (void*)0 + 42;
           ~~~~~~~~ ^

for the Linux kernel, we're using -std=gnu11 -Wno-gnu, so we should not be observing ANY warnings that we're using GNU C extensions.

I suspect that these two checks should be split into two different named command line flags, such that the one pertaining to GNU C extensions is placed within the -Wgnu flag group, such that -Wno-gnu implicitly disables it.

cc @AaronBallman @andykaylor

(link #4440)

As reported in this thread.

Metadata

Metadata

Assignees

Labels

clang: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