r322790 - [analyzer] NFC: operator new: Fix new(nothrow) definition in tests.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 17 16:03:43 PST 2018


Author: dergachev
Date: Wed Jan 17 16:03:43 2018
New Revision: 322790

URL: http://llvm.org/viewvc/llvm-project?rev=322790&view=rev
Log:
[analyzer] NFC: operator new: Fix new(nothrow) definition in tests.

Fix the const qualifier so that the operator defined in the tests indeed does
override the default global nothrow version of new.

Differential Revision: https://reviews.llvm.org/D41408

Modified:
    cfe/trunk/test/Analysis/NewDelete-custom.cpp

Modified: cfe/trunk/test/Analysis/NewDelete-custom.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/NewDelete-custom.cpp?rev=322790&r1=322789&r2=322790&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/NewDelete-custom.cpp (original)
+++ cfe/trunk/test/Analysis/NewDelete-custom.cpp Wed Jan 17 16:03:43 2018
@@ -4,7 +4,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=true -DLEAKS=1 -DALLOCATOR_INLINING=1 -fblocks -verify %s
 #include "Inputs/system-header-simulator-cxx.h"
 
-#if !LEAKS
+#if !(LEAKS && !ALLOCATOR_INLINING)
 // expected-no-diagnostics
 #endif
 
@@ -13,7 +13,7 @@ void *allocator(std::size_t size);
 
 void *operator new[](std::size_t size) throw() { return allocator(size); }
 void *operator new(std::size_t size) throw() { return allocator(size); }
-void *operator new(std::size_t size, std::nothrow_t& nothrow) throw() { return allocator(size); }
+void *operator new(std::size_t size, const std::nothrow_t &nothrow) throw() { return allocator(size); }
 void *operator new(std::size_t, double d);
 
 class C {
@@ -59,16 +59,13 @@ void testNewExpr() {
 
 //----- Custom NoThrow placement operators
 void testOpNewNoThrow() {
-  void *p = operator new(0, std::nothrow);
+  void *p = operator new(0, std::nothrow); // call is inlined, no warn
 }
-#if LEAKS
-// expected-warning at -2{{Potential leak of memory pointed to by 'p'}}
-#endif
 
 void testNewExprNoThrow() {
   int *p = new(std::nothrow) int;
 }
-#if LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning at -2{{Potential leak of memory pointed to by 'p'}}
 #endif
 




More information about the cfe-commits mailing list