From 93023f35f7d9a6ccbc6bb121fb5b95171678924b Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 7 Sep 2015 18:17:23 +0100 Subject: [PATCH] Relax Debug Mode assertions on operator-> for smart pointers. * include/bits/shared_ptr_base.h (__shared_ptr::operator->): Change _GLIBCXX_DEBUG_ASSERT to _GLIBCXX_DEBUG_PEDASSERT. * include/bits/unique_ptr.h (unique_ptr::operator->): Likewise. * testsuite/20_util/shared_ptr/observers/get.cc: Test operator-> on empty shared_ptr. From-SVN: r227524 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/bits/shared_ptr_base.h | 2 +- libstdc++-v3/include/bits/unique_ptr.h | 2 +- .../testsuite/20_util/shared_ptr/observers/get.cc | 13 +++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 91e3c356b20..91d2957437e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,11 @@ 2015-09-07 Jonathan Wakely + * include/bits/shared_ptr_base.h (__shared_ptr::operator->): Change + _GLIBCXX_DEBUG_ASSERT to _GLIBCXX_DEBUG_PEDASSERT. + * include/bits/unique_ptr.h (unique_ptr::operator->): Likewise. + * testsuite/20_util/shared_ptr/observers/get.cc: Test operator-> on + empty shared_ptr. + * include/bits/regex_compiler.h (_BracketMatcher::_M_is_ready): Initialize using NSDMI and set using _GLIBCXX_DEBUG_ONLY. diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index f2f577b9115..75f1a0d489b 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1054,7 +1054,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Tp* operator->() const noexcept { - _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0); + _GLIBCXX_DEBUG_PEDASSERT(_M_ptr != 0); return _M_ptr; } diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index 8ab55da75d3..bb96951e4ae 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -295,7 +295,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION pointer operator->() const noexcept { - _GLIBCXX_DEBUG_ASSERT(get() != pointer()); + _GLIBCXX_DEBUG_PEDASSERT(get() != pointer()); return get(); } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/observers/get.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/get.cc index 85fc71dfd39..867f07a679f 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/observers/get.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/observers/get.cc @@ -63,11 +63,24 @@ test03() VERIFY( &p->i == &a->i ); } +void +test04() +{ + bool test __attribute__((unused)) = true; + +#if !(defined _GLIBCXX_DEBUG && defined _GLIBCXX_DEBUG_PEDANTIC) + std::shared_ptr p; + auto np = p.operator->(); + VERIFY( np == nullptr ); +#endif +} + int main() { test01(); test02(); test03(); + test04(); return 0; } -- 2.30.2