Skip to content

Wrong "warning: subtraction of pointers to type 'int [n]' of zero size has undefined behavior [-Wpointer-arith]" #28328

Open
@llvmbot

Description

Bugzilla Link 27954
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor

Extended Description

Source code:


#include <stdio.h>

int main()
{
int n = 1;
int a[n];
(void)(&a + 1 - &a);

printf("sizeof(int [n]) = %zu\n", sizeof(int [n]));
}

Results:


$ clang -std=c11 -Weverything -Wno-vla -O3 test.c && ./a.out
test.c:7:17: warning: subtraction of pointers to type 'int [n]' of zero size has undefined behavior [-Wpointer-arith]
(void)(&a + 1 - &a);
~~~~~~ ^ ~~
1 warning generated.
sizeof(int [n]) = 4

clang version: clang version 3.9.0 (trunk 271312)

The warning talks about zero size but the size of type 'int [n]' is not zero as illustrated by the result of printf. The warning is wrong.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac99clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second partyfalse-positiveWarning fires when it should notquality-of-implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions