[libcxx] r300121 - Fix incorrectly qualified return type from unique_ptr::get_deleter().
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 12 15:43:50 PDT 2017
Author: ericwf
Date: Wed Apr 12 17:43:49 2017
New Revision: 300121
URL: http://llvm.org/viewvc/llvm-project?rev=300121&view=rev
Log:
Fix incorrectly qualified return type from unique_ptr::get_deleter().
For reference deleter types the const qualifier on the return type
of get_deleter() should be ignored, and a non-const deleter should
be returned.
This patch fixes a bug where "const deleter_type&" is incorrectly
formed.
Modified:
libcxx/trunk/include/memory
libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp
libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp
libcxx/trunk/test/support/test_macros.h
Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=300121&r1=300120&r2=300121&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Wed Apr 12 17:43:49 2017
@@ -2110,8 +2110,8 @@ public:
typedef typename remove_reference<_T1>::type& _T1_reference;
typedef typename remove_reference<_T2>::type& _T2_reference;
- typedef const typename remove_reference<_T1>::type& _T1_const_reference;
- typedef const typename remove_reference<_T2>::type& _T2_const_reference;
+ typedef typename remove_reference<typename add_const<_T1>::type>::type& _T1_const_reference;
+ typedef typename remove_reference<typename add_const<_T2>::type>::type& _T2_const_reference;
_LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {}
_LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
@@ -2166,7 +2166,8 @@ public:
typedef typename remove_reference<_T2>::type& _T2_reference;
typedef const _T1& _T1_const_reference;
- typedef const typename remove_reference<_T2>::type& _T2_const_reference;
+ typedef typename remove_reference<typename add_const<_T2>::type>::type&
+ _T2_const_reference;
_LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {}
_LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
@@ -2219,7 +2220,8 @@ public:
typedef typename remove_reference<_T1>::type& _T1_reference;
typedef _T2& _T2_reference;
- typedef const typename remove_reference<_T1>::type& _T1_const_reference;
+ typedef typename remove_reference<typename add_const<_T1>::type>::type&
+ _T1_const_reference;
typedef const _T2& _T2_const_reference;
_LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {}
@@ -2459,8 +2461,9 @@ private:
struct __nat {int __for_bool_;};
- typedef typename remove_reference<deleter_type>::type& _Dp_reference;
- typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
+ typedef typename remove_reference<deleter_type>::type& _Dp_reference;
+ typedef typename remove_reference<typename add_const<deleter_type>::type>::type&
+ _Dp_const_reference;
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
: __ptr_(pointer())
@@ -2648,8 +2651,9 @@ private:
struct __nat {int __for_bool_;};
- typedef typename remove_reference<deleter_type>::type& _Dp_reference;
- typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
+ typedef typename remove_reference<deleter_type>::type& _Dp_reference;
+ typedef typename remove_reference<typename add_const<deleter_type>::type>::type&
+ _Dp_const_reference;
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
: __ptr_(pointer())
Modified: libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp?rev=300121&r1=300120&r2=300121&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp Wed Apr 12 17:43:49 2017
@@ -15,23 +15,42 @@
#include <memory>
#include <cassert>
+#include "test_macros.h"
-struct Deleter
-{
- void operator()(void*) {}
+struct Deleter {
+ void operator()(void*) const {}
- int test() {return 5;}
- int test() const {return 6;}
+ int test() { return 5; }
+ int test() const { return 6; }
};
-int main()
-{
- {
+int main() {
+ {
std::unique_ptr<int[], Deleter> p;
assert(p.get_deleter().test() == 5);
- }
- {
+ }
+ {
const std::unique_ptr<int[], Deleter> p;
assert(p.get_deleter().test() == 6);
- }
+ }
+ {
+ typedef std::unique_ptr<int[], const Deleter&> UPtr;
+ const Deleter d;
+ UPtr p(nullptr, d);
+ const UPtr& cp = p;
+ ASSERT_SAME_TYPE(decltype(p.get_deleter()), const Deleter&);
+ ASSERT_SAME_TYPE(decltype(cp.get_deleter()), const Deleter&);
+ assert(p.get_deleter().test() == 6);
+ assert(cp.get_deleter().test() == 6);
+ }
+ {
+ typedef std::unique_ptr<int[], Deleter&> UPtr;
+ Deleter d;
+ UPtr p(nullptr, d);
+ const UPtr& cp = p;
+ ASSERT_SAME_TYPE(decltype(p.get_deleter()), Deleter&);
+ ASSERT_SAME_TYPE(decltype(cp.get_deleter()), Deleter&);
+ assert(p.get_deleter().test() == 5);
+ assert(cp.get_deleter().test() == 5);
+ }
}
Modified: libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp?rev=300121&r1=300120&r2=300121&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp Wed Apr 12 17:43:49 2017
@@ -15,23 +15,42 @@
#include <memory>
#include <cassert>
+#include "test_macros.h"
-struct Deleter
-{
- void operator()(void*) {}
+struct Deleter {
+ void operator()(void*) const {}
- int test() {return 5;}
- int test() const {return 6;}
+ int test() { return 5; }
+ int test() const { return 6; }
};
-int main()
-{
- {
+int main() {
+ {
std::unique_ptr<int, Deleter> p;
assert(p.get_deleter().test() == 5);
- }
- {
+ }
+ {
const std::unique_ptr<int, Deleter> p;
assert(p.get_deleter().test() == 6);
- }
+ }
+ {
+ typedef std::unique_ptr<int, const Deleter&> UPtr;
+ const Deleter d;
+ UPtr p(nullptr, d);
+ const UPtr& cp = p;
+ ASSERT_SAME_TYPE(decltype(p.get_deleter()), const Deleter&);
+ ASSERT_SAME_TYPE(decltype(cp.get_deleter()), const Deleter&);
+ assert(p.get_deleter().test() == 6);
+ assert(cp.get_deleter().test() == 6);
+ }
+ {
+ typedef std::unique_ptr<int, Deleter&> UPtr;
+ Deleter d;
+ UPtr p(nullptr, d);
+ const UPtr& cp = p;
+ ASSERT_SAME_TYPE(decltype(p.get_deleter()), Deleter&);
+ ASSERT_SAME_TYPE(decltype(cp.get_deleter()), Deleter&);
+ assert(p.get_deleter().test() == 5);
+ assert(cp.get_deleter().test() == 5);
+ }
}
Modified: libcxx/trunk/test/support/test_macros.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_macros.h?rev=300121&r1=300120&r2=300121&view=diff
==============================================================================
--- libcxx/trunk/test/support/test_macros.h (original)
+++ libcxx/trunk/test/support/test_macros.h Wed Apr 12 17:43:49 2017
@@ -184,7 +184,7 @@ struct is_same<T, T> { enum {value = 1};
} // namespace test_macros_detail
#define ASSERT_SAME_TYPE(...) \
- static_assert(test_macros_detail::is_same<__VA_ARGS__>::value, \
+ static_assert((test_macros_detail::is_same<__VA_ARGS__>::value), \
"Types differ uexpectedly")
#ifndef TEST_HAS_NO_EXCEPTIONS
More information about the cfe-commits
mailing list