1 | // RUN: %clang_cc1 %s -verify -Wsizeof-pointer-div -fsyntax-only |
2 | |
3 | template <typename Ty, int N> |
4 | int f(Ty (&Array)[N]) { |
5 | return sizeof(Array) / sizeof(Ty); // Should not warn |
6 | } |
7 | |
8 | void test(int *p, int **q) { |
9 | int a1 = sizeof(p) / sizeof(*p); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} |
10 | int a2 = sizeof p / sizeof *p; // expected-warning {{'sizeof p' will return the size of the pointer, not the array itself}} |
11 | int a3 = sizeof(*q) / sizeof(**q); // expected-warning {{'sizeof (*q)' will return the size of the pointer, not the array itself}} |
12 | int a4 = sizeof(p) / sizeof(int); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} |
13 | int a5 = sizeof(p) / sizeof(p[0]); // expected-warning {{'sizeof (p)' will return the size of the pointer, not the array itself}} |
14 | |
15 | // Should not warn |
16 | int b1 = sizeof(int *) / sizeof(int); |
17 | int b2 = sizeof(p) / sizeof(p); |
18 | int b3 = sizeof(*q) / sizeof(q); |
19 | int b4 = sizeof(p) / sizeof(char); |
20 | |
21 | int arr[10]; |
22 | int b5 = sizeof(arr) / sizeof(*arr); |
23 | int b6 = sizeof(arr) / sizeof(arr[0]); |
24 | int b7 = sizeof(arr) / sizeof(int); |
25 | |
26 | int arr2[10][12]; |
27 | int b8 = sizeof(arr2) / sizeof(*arr2); |
28 | } |
29 | |