Index: base/tools_sanity_unittest.cc |
diff --git a/base/tools_sanity_unittest.cc b/base/tools_sanity_unittest.cc |
index 2ddaf89dd490806d5941051710b78c6b6d923487..c0541d139fb48b22c3425b02de90b10dedff7017 100644 |
--- a/base/tools_sanity_unittest.cc |
+++ b/base/tools_sanity_unittest.cc |
@@ -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; |
} |