[libcxx] r342936 - Remove redundant null pointer check in operator delete

Fangrui Song maskray at google.com
Mon Sep 24 19:50:58 PDT 2018


Author: maskray
Date: Mon Sep 24 19:50:57 2018
New Revision: 342936

URL: http://llvm.org/viewvc/llvm-project?rev=342936&view=rev
Log:
Remove redundant null pointer check in operator delete

C89 4.10.3.2 The free function
C99 7.20.3.2 The free function
C11 7.22.3.3 The free function

    If ptr is a null pointer, no action shall occur.

_aligned_free on MSDN:

    If memblock is a NULL pointer, this function simply performs no actions.

Reviewers: EricWF, mclow.lists

Subscribers: christof, ldionne, cfe-commits, libcxx-commits

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

Modified:
    libcxx/trunk/src/new.cpp

Modified: libcxx/trunk/src/new.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/new.cpp?rev=342936&r1=342935&r2=342936&view=diff
==============================================================================
--- libcxx/trunk/src/new.cpp (original)
+++ libcxx/trunk/src/new.cpp Mon Sep 24 19:50:57 2018
@@ -135,8 +135,7 @@ _LIBCPP_WEAK
 void
 operator delete(void* ptr) _NOEXCEPT
 {
-    if (ptr)
-        ::free(ptr);
+    ::free(ptr);
 }
 
 _LIBCPP_WEAK
@@ -257,11 +256,10 @@ _LIBCPP_WEAK
 void
 operator delete(void* ptr, std::align_val_t) _NOEXCEPT
 {
-    if (ptr)
 #if defined(_LIBCPP_MSVCRT_LIKE)
-        ::_aligned_free(ptr);
+    ::_aligned_free(ptr);
 #else
-        ::free(ptr);
+    ::free(ptr);
 #endif
 }
 




More information about the libcxx-commits mailing list