xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/warn-sizeof-array-decay.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
f(int x)3*f4a2713aSLionel Sambuc void f(int x) {
4*f4a2713aSLionel Sambuc   char foo[10];
5*f4a2713aSLionel Sambuc   int bar[20];
6*f4a2713aSLionel Sambuc   char qux[30];
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc   (void)sizeof(bar + 10); // expected-warning{{sizeof on pointer operation will return size of 'int *' instead of 'int [20]'}}
9*f4a2713aSLionel Sambuc   (void)sizeof(foo - 20); // expected-warning{{sizeof on pointer operation will return size of 'char *' instead of 'char [10]'}}
10*f4a2713aSLionel Sambuc   (void)sizeof(bar - x); // expected-warning{{sizeof on pointer operation will return size of 'int *' instead of 'int [20]'}}
11*f4a2713aSLionel Sambuc   (void)sizeof(foo + x); // expected-warning{{sizeof on pointer operation will return size of 'char *' instead of 'char [10]'}}
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc   // This is ptrdiff_t.
14*f4a2713aSLionel Sambuc   (void)sizeof(foo - qux); // no-warning
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc   (void)sizeof(foo, x); // no-warning
17*f4a2713aSLionel Sambuc   (void)sizeof(x, foo); // expected-warning{{sizeof on pointer operation will return size of 'char *' instead of 'char [10]'}}
18*f4a2713aSLionel Sambuc }
19