-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[-Wunsafe-buffer-usage] Add unique_ptr <T[]> accesses #156773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
927b2f6
bae5f2e
284c262
980a75e
11fc596
800d393
4c95972
38a2d44
dd1ab78
aacc510
f074fd0
5bc6580
766be17
eb9afef
efb19b6
7cefe30
6cf2c9f
f805faf
db8a2bc
9d597ed
2b823cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ template <class T> class unique_ptr { | |
|
||
void basic_unique_ptr() { | ||
|
||
std::unique_ptr<int[]> p1; | ||
p1[0]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
p1[1]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
} | ||
|
||
// CHECK: Root # 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// RUN: %clang_cc1 -Wno-unused-value -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions -std=c++20 -verify=expected %s | ||
|
||
// This debugging facility is only available in debug builds. | ||
shreya-jain marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// | ||
// REQUIRES: asserts | ||
|
||
namespace std { | ||
inline namespace __1 { | ||
template <class T> class unique_ptr { | ||
public: | ||
T &operator[](long long i) const; | ||
}; | ||
} // namespace __1 | ||
} // namespace std | ||
|
||
void basic_unique_ptr() { | ||
std::unique_ptr<int[]> p1; | ||
int i = 2; | ||
|
||
p1[0]; // This is allowed | ||
|
||
p1[1]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
|
||
p1[i]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
|
||
p1[i + 5]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
} | ||
|
||
// CHECK: Root # 1 | ||
shreya-jain marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// CHECK: |- DeclRefExpr # 4 | ||
// CHECK: |-- UnaryOperator(++) # 1 | ||
// CHECK: |--- CompoundStmt # 1 | ||
// CHECK: |-- ImplicitCastExpr(LValueToRValue) # 1 | ||
// CHECK: |--- BinaryOperator(+) # 1 | ||
// CHECK: |---- ParenExpr # 1 | ||
// CHECK: |----- BinaryOperator(+) # 1 | ||
// CHECK: |------ ParenExpr # 1 | ||
// CHECK: |------- UnaryOperator(*) # 1 | ||
// CHECK: |-------- CompoundStmt # 1 | ||
// CHECK: |-- BinaryOperator(-=) # 1 | ||
// CHECK: |--- CompoundStmt # 1 | ||
// CHECK: |-- UnaryOperator(--) # 1 | ||
// CHECK: |--- CompoundStmt # 1 |
Uh oh!
There was an error while loading. Please reload this page.