| 1 |
// RUN: %clang_cc1 -Wno-unused-value -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions -std=c++20 -verify=expected %s |
| 2 |
|
| 3 |
namespace std { |
| 4 |
inline namespace __1 { |
| 5 |
template <class T> class unique_ptr { |
| 6 |
public: |
| 7 |
T &operator[](long long i) const; |
| 8 |
}; |
| 9 |
} // namespace __1 |
| 10 |
} // namespace std |
| 11 |
|
| 12 |
int get_index() { |
| 13 |
return 4; |
| 14 |
} |
| 15 |
|
| 16 |
void basic_unique_ptr() { |
| 17 |
std::unique_ptr<int[]> p1; |
| 18 |
int i = 2; |
| 19 |
const int j = 3; |
| 20 |
int k = 0; |
| 21 |
|
| 22 |
p1[0]; // This is allowed |
| 23 |
|
| 24 |
p1[k]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} |
| 25 |
|
| 26 |
p1[1]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} |
| 27 |
|
| 28 |
p1[1L]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} |
| 29 |
|
| 30 |
p1[1LL]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} |
| 31 |
|
| 32 |
p1[3 * 5]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} |
| 33 |
|
| 34 |
p1[i]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} |
| 35 |
|
| 36 |
p1[j]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} |
| 37 |
|
| 38 |
p1[i + 5]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} |
| 39 |
|
| 40 |
p1[get_index()]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} |
| 41 |
|
| 42 |
} |
| 43 |
|