Author: ahatanak
Date: Mon Jun 26 10:39:48 2017
New Revision: 306310

URL: http://llvm.org/viewvc/llvm-project?rev=306310&view=rev
Log:
[libcxx] Annotate c++17 aligned new/delete operators with availability
attribute.

This is needed because older versions of libc++ do not have these
operators. If users target an older deployment target and try to compile
programs in which these operators are explicitly called, the compiler
will complain.

The following is the list of minimum deployment targets for the four
OSes:

macosx: 10.13
ios: 11.0
tvos: 11.0
watchos: 4.0

rdar://problem/32664169

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

Added:
    
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp
Modified:
    libcxx/trunk/include/__config
    libcxx/trunk/include/new

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=306310&r1=306309&r2=306310&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Mon Jun 26 10:39:48 2017
@@ -1176,6 +1176,11 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 #define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR                                 
\
   __attribute__((availability(macosx,strict,introduced=10.9)))                 
\
   __attribute__((availability(ios,strict,introduced=7.0)))
+#define _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION                                
\
+  __attribute__((availability(macosx,strict,introduced=10.13)))                
\
+  __attribute__((availability(ios,strict,introduced=11.0)))                    
\
+  __attribute__((availability(tvos,strict,introduced=11.0)))                   
\
+  __attribute__((availability(watchos,strict,introduced=4.0)))
 #else
 #define _LIBCPP_AVAILABILITY_SHARED_MUTEX
 #define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
@@ -1187,6 +1192,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 #define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE
 #define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
 #define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
+#define _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION
 #endif
 
 // Define availability that depends on _LIBCPP_NO_EXCEPTIONS.

Modified: libcxx/trunk/include/new
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/new?rev=306310&r1=306309&r2=306310&view=diff
==============================================================================
--- libcxx/trunk/include/new (original)
+++ libcxx/trunk/include/new Mon Jun 26 10:39:48 2017
@@ -193,20 +193,20 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVA
 #endif
 
 #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, 
std::align_val_t) _THROW_BAD_ALLOC;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, 
std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p, 
std::align_val_t) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p, 
std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void* 
operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void* 
operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) 
_NOEXCEPT _NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  
operator delete(void* __p, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  
operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
 #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void  
operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  
operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
 #endif
 
-_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, 
std::align_val_t) _THROW_BAD_ALLOC;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, 
std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, 
std::align_val_t) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, 
std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void* 
operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void* 
operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) 
_NOEXCEPT _NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  
operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  
operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
 #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void  
operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  
operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
 #endif
 #endif
 

Added: 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp?rev=306310&view=auto
==============================================================================
--- 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp
 (added)
+++ 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp
 Mon Jun 26 10:39:48 2017
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// REQUIRES: availability=macosx10.12
+
+// test availability of new/delete operators introduced in c++17.
+
+#include <new>
+
+int main () {
+  int *p0 = new ((std::align_val_t)16) int(1);
+  (void)p0;
+  int *p1 = new ((std::align_val_t)16) int[1];
+  (void)p1;
+  // expected-error@-4 {{call to unavailable function 'operator new': 
introduced in macOS 10.13}}
+  // expected-note@new:* {{candidate function has been explicitly made 
unavailable}}
+  // expected-note@new:* {{candidate function not viable: no known conversion 
from 'std::align_val_t' to 'const std::nothrow_t' for 2nd argument}}
+  // expected-note@new:* {{candidate function not viable: no known conversion 
from 'std::align_val_t' to 'void *' for 2nd argument}}
+  // expected-note@new:* {{candidate function not viable: requires single 
argument '__sz', but 2 arguments were provided}}
+  // expected-note@new:* {{candidate function not viable: requires 3 
arguments, but 2 were provided}}
+
+  // expected-error@-9 {{call to unavailable function 'operator new[]': 
introduced in macOS 10.13}}
+  // expected-note@new:* {{candidate function has been explicitly made 
unavailable}}
+  // expected-note@new:* {{candidate function not viable: no known conversion 
from 'std::align_val_t' to 'const std::nothrow_t' for 2nd argument}}
+  // expected-note@new:* {{candidate function not viable: no known conversion 
from 'std::align_val_t' to 'void *' for 2nd argument}}
+  // expected-note@new:* {{candidate function not viable: requires single 
argument '__sz', but 2 arguments were provided}}
+  // expected-note@new:* {{candidate function not viable: requires 3 
arguments, but 2 were provided}}
+  return 0;
+}


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to