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 6 {{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 int a10 = sizeof(p) / sizeof(decltype(*p)); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}}
25
26 // Should not warn
27 int b1 = sizeof(int *) / sizeof(int);
28 int b2 = sizeof(p) / sizeof(p);
29 int b3 = sizeof(*q) / sizeof(q);
30 int b4 = sizeof(p) / sizeof(char);
31
32 int arr[10];
33 int c1 = sizeof(arr) / sizeof(*arr);
34 int c2 = sizeof(arr) / sizeof(arr[0]);
35 int c3 = sizeof(arr) / sizeof(int);
36
37 int arr2[10][12];
38 int d1 = sizeof(arr2) / sizeof(*arr2);
39 }
40