1 // RUN: %clang_cc1 %s -verify -Wsizeof-pointer-div -fsyntax-only
2
3 template <typename Ty, int N>
f(Ty (& Array)[N])4 int f(Ty (&Array)[N]) {
5 return sizeof(Array) / sizeof(Ty); // Should not warn
6 }
7
8 typedef int int32;
9
test(int * p,int ** q)10 void test(int *p, int **q) { // expected-note 5 {{pointer 'p' declared here}}
11 const int *r; // expected-note {{pointer 'r' declared here}}
12 int a1 = sizeof(p) / sizeof(*p); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}}
13 int a2 = sizeof p / sizeof *p; // expected-warning {{'sizeof p' will return the size of the pointer, not the array itself}}
14 int a3 = sizeof(p) / sizeof(int); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}}
15 int a4 = sizeof(p) / sizeof(p[0]); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}}
16 int a5 = sizeof(p) / sizeof(int32); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}}
17 int a6 = sizeof(r) / sizeof(int); // expected-warning {{'sizeof (r)' will return the size of the pointer, not the array itself}}
18
19 int32 *d; // expected-note 2 {{pointer 'd' declared here}}
20 int a7 = sizeof(d) / sizeof(int32); // expected-warning {{'sizeof (d)' will return the size of the pointer, not the array itself}}
21 int a8 = sizeof(d) / sizeof(int); // expected-warning {{'sizeof (d)' will return the size of the pointer, not the array itself}}
22
23 int a9 = sizeof(*q) / sizeof(**q); // expected-warning {{'sizeof (*q)' will return the size of the pointer, not the array itself}}
24
25 // Should not warn
26 int b1 = sizeof(int *) / sizeof(int);
27 int b2 = sizeof(p) / sizeof(p);
28 int b3 = sizeof(*q) / sizeof(q);
29 int b4 = sizeof(p) / sizeof(char);
30
31 int arr[10];
32 int c1 = sizeof(arr) / sizeof(*arr);
33 int c2 = sizeof(arr) / sizeof(arr[0]);
34 int c3 = sizeof(arr) / sizeof(int);
35
36 int arr2[10][12];
37 int d1 = sizeof(arr2) / sizeof(*arr2);
38 }
39