Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1434)

Unified Diff: base/tools_sanity_unittest.cc

Issue 1131513006: Work around Clang's new -Wmismatched-new-delete warning. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/debug/stack_trace_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « base/debug/stack_trace_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698