Commit cd4cce34 authored by hans's avatar hans Committed by Commit bot

Work around Clang's new -Wmismatched-new-delete warning.

In r237368, Clang started warning about mismatched operator new[] and delete
calls. This pacifies the warning by moving the operator new-call to a separate
function.

BUG=none

Review URL: https://codereview.chromium.org/1131513006

Cr-Commit-Position: refs/heads/master@{#330528}
parent ed3c5ff2
......@@ -135,8 +135,14 @@ TEST_F(StackTraceTest, DebugPrintBacktrace) {
#if defined(OS_POSIX) && !defined(OS_ANDROID)
#if !defined(OS_IOS)
static char* newArray() {
// Clang warns about the mismatched new[]/delete if they occur in the same
// function.
return new char[10];
}
MULTIPROCESS_TEST_MAIN(MismatchedMallocChildProcess) {
char* pointer = new char[10];
char* pointer = newArray();
delete pointer;
return 2;
}
......
......@@ -145,6 +145,12 @@ TEST(ToolsSanityTest, MAYBE_AccessesToMallocMemory) {
HARMFUL_ACCESS(foo[5] = 0, "heap-use-after-free");
}
static int* allocateArray() {
// Clang warns about the mismatched new[]/delete if they occur in the same
// function.
return new int[10];
}
TEST(ToolsSanityTest, MAYBE_ArrayDeletedWithoutBraces) {
#if !defined(ADDRESS_SANITIZER) && !defined(SYZYASAN)
// This test may corrupt memory if not run under Valgrind or compiled with
......@@ -154,10 +160,16 @@ TEST(ToolsSanityTest, MAYBE_ArrayDeletedWithoutBraces) {
#endif
// Without the |volatile|, clang optimizes away the next two lines.
int* volatile foo = new int[10];
int* volatile foo = allocateArray();
delete foo;
}
static int* allocateScalar() {
// Clang warns about the mismatched new/delete[] if they occur in the same
// function.
return new int;
}
TEST(ToolsSanityTest, MAYBE_SingleElementDeletedWithBraces) {
#if !defined(ADDRESS_SANITIZER)
// This test may corrupt memory if not run under Valgrind or compiled with
......@@ -167,7 +179,7 @@ TEST(ToolsSanityTest, MAYBE_SingleElementDeletedWithBraces) {
#endif
// Without the |volatile|, clang optimizes away the next two lines.
int* volatile foo = new int;
int* volatile foo = allocateScalar();
(void) foo;
delete [] foo;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment