Wrong "warning: subtraction of pointers to type 'int [n]' of zero size has undefined behavior [-Wpointer-arith]" #28328
Open
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