mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-04 16:41:43 +00:00

Emit warning when operand to `delete` is allocated with `new[]` or operand to `delete[]` is allocated with `new`. rev 2 update: `getNewExprFromInitListOrExpr` should return `dyn_cast_or_null` instead of `dyn_cast`, since `E` might be null. Reviewers: rtrieu, jordan_rose, rsmith Subscribers: majnemer, cfe-commits Differential Revision: http://reviews.llvm.org/D4661 llvm-svn: 237608
16 lines
385 B
C++
16 lines
385 B
C++
// Header for PCH test delete.cpp
|
|
namespace pch_test {
|
|
struct X {
|
|
int *a;
|
|
X();
|
|
X(int);
|
|
X(bool)
|
|
: a(new int[1]) { } // expected-note{{allocated with 'new[]' here}}
|
|
~X()
|
|
{
|
|
delete a; // expected-warning{{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:9}:"[]"
|
|
}
|
|
};
|
|
}
|