[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / div-sizeof-ptr.cpp
blobdcb05ccd0162b89da0fcdc46c21c12f7f7c0d832
1 // RUN: %clang_cc1 %s -verify -Wsizeof-pointer-div -fsyntax-only
3 template <typename Ty, int N>
4 int f(Ty (&Array)[N]) {
5 return sizeof(Array) / sizeof(Ty); // Should not warn
8 typedef int int32;
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}}
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}}
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}}
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);
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);
37 int arr2[10][12];
38 int d1 = sizeof(arr2) / sizeof(*arr2);