[libcxx-commits] [libcxx] a134173 - [libc++] Properly mark std::function as deprecated in C++03

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 10 14:45:45 PDT 2020


Author: Louis Dionne
Date: 2020-03-10T17:45:39-04:00
New Revision: a13417352ade3bf2ef68cabcde1dc480746644ad

URL: https://github.com/llvm/llvm-project/commit/a13417352ade3bf2ef68cabcde1dc480746644ad
DIFF: https://github.com/llvm/llvm-project/commit/a13417352ade3bf2ef68cabcde1dc480746644ad.diff

LOG: [libc++] Properly mark std::function as deprecated in C++03

Due to Clang bug http://llvm.org/PR45151, deprecated attributes are not
picked up on partial specializations. This patch instead applies it to
the first declaration of std::function itself.

Added: 
    libcxx/test/libcxx/utilities/function.objects/func.wrap/depr_in_cxx03.fail.cpp

Modified: 
    libcxx/include/__functional_03
    libcxx/include/functional

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__functional_03 b/libcxx/include/__functional_03
index f945aa5bc4d9..bf86428dea05 100644
--- a/libcxx/include/__functional_03
+++ b/libcxx/include/__functional_03
@@ -443,15 +443,8 @@ __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const
 
 }  // __function
 
-#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)
-#   define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
-        __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a 
diff erent type")))
-#else
-#   define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
-#endif
-
 template<class _Rp>
-class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function<_Rp()>
+class _LIBCPP_TEMPLATE_VIS function<_Rp()>
 {
     typedef __function::__base<_Rp()> __base;
     aligned_storage<3*sizeof(void*)>::type __buf_;
@@ -730,7 +723,7 @@ function<_Rp()>::target() const
 #endif  // _LIBCPP_NO_RTTI
 
 template<class _Rp, class _A0>
-class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function<_Rp(_A0)>
+class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0)>
     : public unary_function<_A0, _Rp>
 {
     typedef __function::__base<_Rp(_A0)> __base;
@@ -1010,7 +1003,7 @@ function<_Rp(_A0)>::target() const
 #endif  // _LIBCPP_NO_RTTI
 
 template<class _Rp, class _A0, class _A1>
-class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1)>
+class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1)>
     : public binary_function<_A0, _A1, _Rp>
 {
     typedef __function::__base<_Rp(_A0, _A1)> __base;
@@ -1290,7 +1283,7 @@ function<_Rp(_A0, _A1)>::target() const
 #endif  // _LIBCPP_NO_RTTI
 
 template<class _Rp, class _A0, class _A1, class _A2>
-class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1, _A2)>
+class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1, _A2)>
 {
     typedef __function::__base<_Rp(_A0, _A1, _A2)> __base;
     aligned_storage<3*sizeof(void*)>::type __buf_;

diff  --git a/libcxx/include/functional b/libcxx/include/functional
index 865a28123b97..63e3cbed046a 100644
--- a/libcxx/include/functional
+++ b/libcxx/include/functional
@@ -1434,7 +1434,14 @@ void __throw_bad_function_call()
 #endif
 }
 
-template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined
+#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)
+#   define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
+        __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a 
diff erent type")))
+#else
+#   define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
+#endif
+
+template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
 
 namespace __function
 {

diff  --git a/libcxx/test/libcxx/utilities/function.objects/func.wrap/depr_in_cxx03.fail.cpp b/libcxx/test/libcxx/utilities/function.objects/func.wrap/depr_in_cxx03.fail.cpp
new file mode 100644
index 000000000000..282a7112cced
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/function.objects/func.wrap/depr_in_cxx03.fail.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <functional>
+
+// Check that libc++'s emulation of std::function is deprecated in C++03
+
+// REQUIRES: c++98 || c++03
+// REQUIRES: verify-support
+
+#include <functional>
+#include "test_macros.h"
+
+int main() {
+    // Note:
+    // We use sizeof() to require it to be a complete type. We don't create a
+    // variable because otherwise we get two errors for each variable (the
+    // second error is when the destructor is implicitly called).
+    (void)sizeof(std::function<void ()>); // expected-error{{'function<void ()>' is deprecated}}
+    (void)sizeof(std::function<void (int)>); // expected-error{{'function<void (int)>' is deprecated}}
+    (void)sizeof(std::function<void (int, int)>); // expected-error{{'function<void (int, int)>' is deprecated}}
+    (void)sizeof(std::function<void (int, int, int)>); // expected-error{{'function<void (int, int, int)>' is deprecated}}
+}


        


More information about the libcxx-commits mailing list