| 1 |
// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \ |
| 2 |
// RUN: -fsafe-buffer-usage-suggestions \ |
| 3 |
// RUN: -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s |
| 4 |
|
| 5 |
int ptr(unsigned idx) { |
| 6 |
int * ptr = new int[1]; |
| 7 |
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int>" |
| 8 |
int a; |
| 9 |
a = ptr[idx]; |
| 10 |
return a; |
| 11 |
} |
| 12 |
|
| 13 |
int ptr_to_const(unsigned idx) { |
| 14 |
const int * ptr = new int[1]; |
| 15 |
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:14}:"std::span<int const>" |
| 16 |
int a; |
| 17 |
a = ptr[idx]; |
| 18 |
return a; |
| 19 |
} |
| 20 |
|
| 21 |
int const_ptr(unsigned idx) { |
| 22 |
int * const ptr = new int[1]; |
| 23 |
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int>" |
| 24 |
int a; |
| 25 |
a = ptr[idx]; |
| 26 |
return a; |
| 27 |
} |
| 28 |
|
| 29 |
int const_ptr_to_const(unsigned idx) { |
| 30 |
const int * const ptr = new int[1]; |
| 31 |
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:14}:"std::span<int const>" |
| 32 |
int a; |
| 33 |
a = ptr[idx]; |
| 34 |
return a; |
| 35 |
} |
| 36 |
|
| 37 |
int ptr_to_const_volatile(unsigned idx) { |
| 38 |
const volatile int * ptr = new int[1]; |
| 39 |
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:23}:"std::span<int const volatile>" |
| 40 |
int a; |
| 41 |
a = ptr[idx]; |
| 42 |
return a; |
| 43 |
} |
| 44 |
|
| 45 |
int const_volatile_ptr(unsigned idx) { |
| 46 |
int * const volatile ptr = new int[1]; |
| 47 |
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:8}:"std::span<int>" |
| 48 |
int a; |
| 49 |
a = ptr[idx]; |
| 50 |
return a; |
| 51 |
} |
| 52 |
|
| 53 |
int const_volatile_ptr_to_const_volatile(unsigned idx) { |
| 54 |
const volatile int * const volatile ptr = new int[1]; |
| 55 |
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:23}:"std::span<int const volatile>" |
| 56 |
int a; |
| 57 |
a = ptr[idx]; |
| 58 |
return a; |
| 59 |
} |
| 60 |
|
| 61 |
typedef const int * my_const_int_star; |
| 62 |
int typedef_ptr_to_const(unsigned idx) { |
| 63 |
my_const_int_star ptr = new int[1]; |
| 64 |
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]: |
| 65 |
int a; |
| 66 |
a = ptr[idx]; |
| 67 |
return a; |
| 68 |
} |
| 69 |
|
| 70 |
typedef int * const my_int_star_const; |
| 71 |
int typedef_const_ptr(unsigned idx) { |
| 72 |
my_int_star_const ptr = new int[1]; |
| 73 |
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]: |
| 74 |
int a; |
| 75 |
a = ptr[idx]; |
| 76 |
return a; |
| 77 |
} |
| 78 |
|
| 79 |
typedef const int * const my_const_int_star_const; |
| 80 |
int typedef_const_ptr_to_const(unsigned idx) { |
| 81 |
my_const_int_star_const ptr = new int[1]; |
| 82 |
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]: |
| 83 |
int a; |
| 84 |
a = ptr[idx]; |
| 85 |
return a; |
| 86 |
} |
| 87 |
|
| 88 |
int ptr_to_decltype(unsigned idx) { |
| 89 |
int a; |
| 90 |
decltype(a) * ptr = new int[1]; |
| 91 |
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:16}:"std::span<decltype(a)>" |
| 92 |
a = ptr[idx]; |
| 93 |
return a; |
| 94 |
} |
| 95 |
|
| 96 |
int decltype_ptr(unsigned idx) { |
| 97 |
int * p; |
| 98 |
decltype(p) ptr = new int[1]; |
| 99 |
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]: |
| 100 |
int a; |
| 101 |
a = ptr[idx]; |
| 102 |
return a; |
| 103 |
} |