[libcxx] r229281 - Implement C++14's sized deallocation functions, since there are no longer implicitly defined by clang, as of r229241.

Richard Smith richard at metafoo.co.uk
Tue Feb 17 00:22:47 PST 2015


On Mon, Feb 16, 2015 at 5:48 PM, Larisse Voufo <lvoufo at cs.indiana.edu>
wrote:

> On Sun, Feb 15, 2015 at 6:01 PM, Richard Smith <richard at metafoo.co.uk>
> wrote:
>
>> On Sat, Feb 14, 2015 at 9:18 PM, Larisse Voufo <lvoufo at google.com> wrote:
>>
>>> Author: lvoufo
>>> Date: Sat Feb 14 23:18:55 2015
>>> New Revision: 229281
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=229281&view=rev
>>> Log:
>>> Implement C++14's sized deallocation functions, since there are no
>>> longer implicitly defined by clang, as of r229241.
>>>
>>> Modified:
>>>     libcxx/trunk/include/new
>>>     libcxx/trunk/src/new.cpp
>>>
>>> Modified: libcxx/trunk/include/new
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/new?rev=229281&r1=229280&r2=229281&view=diff
>>>
>>> ==============================================================================
>>> --- libcxx/trunk/include/new (original)
>>> +++ libcxx/trunk/include/new Sat Feb 14 23:18:55 2015
>>> @@ -50,12 +50,18 @@ new_handler get_new_handler() noexcept;
>>>  void* operator new(std::size_t size);
>>>  // replaceable
>>>  void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
>>>  // replaceable
>>>  void  operator delete(void* ptr) noexcept;
>>> // replaceable
>>> +void  operator delete(void* ptr, std::size_t size) noexcept;
>>> // replaceable, C++14
>>>  void  operator delete(void* ptr, const std::nothrow_t&) noexcept;
>>>  // replaceable
>>> +void  operator delete(void* ptr, std::size_t size,
>>> +                      const std::nothrow_t&) noexcept;
>>> // replaceable, C++14
>>>
>>>  void* operator new[](std::size_t size);
>>>  // replaceable
>>>  void* operator new[](std::size_t size, const std::nothrow_t&) noexcept;
>>> // replaceable
>>>  void  operator delete[](void* ptr) noexcept;
>>> // replaceable
>>> +void  operator delete[](void* ptr, std::size_t size) noexcept;
>>> // replaceable, C++14
>>>  void  operator delete[](void* ptr, const std::nothrow_t&) noexcept;
>>>  // replaceable
>>> +void  operator delete[](void* ptr, std::size_t size,
>>> +                        const std::nothrow_t&) noexcept;
>>> // replaceable, C++14
>>>
>>>  void* operator new  (std::size_t size, void* ptr) noexcept;
>>>  void* operator new[](std::size_t size, void* ptr) noexcept;
>>> @@ -133,7 +139,9 @@ _LIBCPP_NEW_DELETE_VIS void* operator ne
>>>  ;
>>>  _LIBCPP_NEW_DELETE_VIS void* operator new(std::size_t __sz, const
>>> std::nothrow_t&) _NOEXCEPT _NOALIAS;
>>>  _LIBCPP_NEW_DELETE_VIS void  operator delete(void* __p) _NOEXCEPT;
>>> +_LIBCPP_NEW_DELETE_VIS void  operator delete(void* __p, std::size_t
>>> __sz) _NOEXCEPT;
>>>  _LIBCPP_NEW_DELETE_VIS void  operator delete(void* __p, const
>>> std::nothrow_t&) _NOEXCEPT;
>>> +_LIBCPP_NEW_DELETE_VIS void  operator delete(void* __p, std::size_t
>>> __sz, const std::nothrow_t&) _NOEXCEPT;
>>>
>>>  _LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz)
>>>  #if !__has_feature(cxx_noexcept)
>>> @@ -142,7 +150,9 @@ _LIBCPP_NEW_DELETE_VIS void* operator ne
>>>  ;
>>>  _LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz, const
>>> std::nothrow_t&) _NOEXCEPT _NOALIAS;
>>>  _LIBCPP_NEW_DELETE_VIS void  operator delete[](void* __p) _NOEXCEPT;
>>> +_LIBCPP_NEW_DELETE_VIS void  operator delete[](void* __p, std::size_t
>>> __sz) _NOEXCEPT;
>>>  _LIBCPP_NEW_DELETE_VIS void  operator delete[](void* __p, const
>>> std::nothrow_t&) _NOEXCEPT;
>>> +_LIBCPP_NEW_DELETE_VIS void  operator delete[](void* __p, std::size_t
>>> __sz, const std::nothrow_t&) _NOEXCEPT;
>>>
>>>  inline _LIBCPP_INLINE_VISIBILITY void* operator new  (std::size_t,
>>> void* __p) _NOEXCEPT {return __p;}
>>>  inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t,
>>> void* __p) _NOEXCEPT {return __p;}
>>>
>>
>> These new declarations should be wrapped in a version check; we should
>> only declare them in <new> if we're in C++14 or later.
>>
>
> Clang also supports the -fsized-deallocation flag in C++11 mode. Should we
> factor this in the version check as well, or perhaps
> remove/deprecate it from Clang?
>

I don't think there's any need to care about whether the feature is enabled
in Clang. The non-nothrow forms are implicitly declared by the compiler, so
libc++'s declarations are redundant in all modes (but technically the
standard says they should be there in <new> in C++14, so I suppose we
should include them for completeness). The nothrow forms are useless and
never implicitly called, but we're (currently; I have filed a library
issue) required to provide them.

So I think you should just check whether libc++ is in C++14 mode, and
declare these functions if so.

Modified: libcxx/trunk/src/new.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/new.cpp?rev=229281&r1=229280&r2=229281&view=diff
>>>
>>> ==============================================================================
>>> --- libcxx/trunk/src/new.cpp (original)
>>> +++ libcxx/trunk/src/new.cpp Sat Feb 14 23:18:55 2015
>>> @@ -126,6 +126,13 @@ operator delete(void* ptr) _NOEXCEPT
>>>
>>>  _LIBCPP_WEAK _LIBCPP_NEW_DELETE_VIS
>>>  void
>>> +operator delete(void* ptr, size_t) _NOEXCEPT
>>> +{
>>> +    ::operator delete(ptr);
>>> +}
>>> +
>>> +_LIBCPP_WEAK _LIBCPP_NEW_DELETE_VIS
>>> +void
>>>  operator delete(void* ptr, const std::nothrow_t&) _NOEXCEPT
>>>  {
>>>      ::operator delete(ptr);
>>> @@ -133,9 +140,23 @@ operator delete(void* ptr, const std::no
>>>
>>>  _LIBCPP_WEAK _LIBCPP_NEW_DELETE_VIS
>>>  void
>>> +operator delete(void* ptr, size_t, const std::nothrow_t&) _NOEXCEPT
>>> +{
>>> +    ::operator delete(ptr);
>>> +}
>>> +
>>> +_LIBCPP_WEAK _LIBCPP_NEW_DELETE_VIS
>>> +void
>>>  operator delete[] (void* ptr) _NOEXCEPT
>>>  {
>>> -    ::operator delete (ptr);
>>> +    ::operator delete(ptr);
>>> +}
>>> +
>>> +_LIBCPP_WEAK _LIBCPP_NEW_DELETE_VIS
>>> +void
>>> +operator delete[] (void* ptr, size_t) _NOEXCEPT
>>> +{
>>> +    ::operator delete[](ptr);
>>>  }
>>>
>>>  _LIBCPP_WEAK _LIBCPP_NEW_DELETE_VIS
>>> @@ -144,6 +165,13 @@ operator delete[] (void* ptr, const std:
>>>  {
>>>      ::operator delete[](ptr);
>>>  }
>>> +
>>> +_LIBCPP_WEAK _LIBCPP_NEW_DELETE_VIS
>>> +void
>>> +operator delete[] (void* ptr, size_t, const std::nothrow_t&) _NOEXCEPT
>>> +{
>>> +    ::operator delete[](ptr);
>>> +}
>>>
>>>  #endif // !__GLIBCXX__
>>>
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150217/9199f06e/attachment.html>


More information about the cfe-commits mailing list