[llvm-bugs] [Bug 27954] New: Wrong "warning: subtraction of pointers to type 'int [n]' of zero size has undefined behavior [-Wpointer-arith]"

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 31 14:06:44 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27954

            Bug ID: 27954
           Summary: Wrong "warning: subtraction of pointers to type 'int
                    [n]' of zero size has undefined behavior
                    [-Wpointer-arith]"
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: cherepan at mccme.ru
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160531/20916db2/attachment.html>


More information about the llvm-bugs mailing list