diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2010-08-10 10:08:56 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2010-08-10 10:08:56 +0000 |
commit | 5aadb69b902fee99885e81999ca9d4c2042464ed (patch) | |
tree | 2ff98037ddef320ccc59d8fd077a61a69222b547 | |
parent | e80c2726d26a882c2ef35108b46aa5981a7a4513 (diff) | |
download | gcc-5aadb69b902fee99885e81999ca9d4c2042464ed.zip gcc-5aadb69b902fee99885e81999ca9d4c2042464ed.tar.gz gcc-5aadb69b902fee99885e81999ca9d4c2042464ed.tar.bz2 |
cons_overflow_neg.cc: Avoid -Wall warnings.
2010-08-10 Paolo Carlini <paolo.carlini@oracle.com>
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Avoid -Wall
warnings.
* include/bits/shared_ptr.h (shared_ptr<>::shared_ptr
(const shared_ptr<>&), shared_ptr(shared_ptr<>&&), weak_ptr<>::
weak_ptr(const weak_ptr<>&), weak_ptr(const shared_ptr<>&)):
Constrain appropriately via std::is_convertible, etc.
* include/bits/shared_ptr_base.h: Likewise.
* include/bits/unique_ptr.h (default_delete<>::
default_delete(const default_delete<>&),
unique_ptr<>::unique_ptr(unique_ptr<>&&), operator=(unique_ptr<>&&)):
Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error
line numbers.
* testsuite/20_util/shared_ptr/cons/43820.cc: Likewise.
* include/bits/unique_ptr.h (unique_ptr<>::unique_ptr(auto_ptr<>&&)):
Add.
* include/std/memory: Adjust includes order.
* testsuite/20_util/unique_ptr/cons/auto_ptr.cc: New.
* testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc: Minor tweaks.
From-SVN: r163053
-rw-r--r-- | libstdc++-v3/ChangeLog | 26 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/shared_ptr.h | 15 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/shared_ptr_base.h | 12 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/unique_ptr.h | 31 | ||||
-rw-r--r-- | libstdc++-v3/include/std/memory | 5 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc | 12 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820.cc | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc | 14 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr.cc | 46 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc | 36 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc | 6 |
11 files changed, 167 insertions, 38 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6015568..9a3aaca 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,31 @@ 2010-08-10 Paolo Carlini <paolo.carlini@oracle.com> + * testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Avoid -Wall + warnings. + + * include/bits/shared_ptr.h (shared_ptr<>::shared_ptr + (const shared_ptr<>&), shared_ptr(shared_ptr<>&&), weak_ptr<>:: + weak_ptr(const weak_ptr<>&), weak_ptr(const shared_ptr<>&)): + Constrain appropriately via std::is_convertible, etc. + * include/bits/shared_ptr_base.h: Likewise. + * include/bits/unique_ptr.h (default_delete<>:: + default_delete(const default_delete<>&), + unique_ptr<>::unique_ptr(unique_ptr<>&&), operator=(unique_ptr<>&&)): + Likewise. + + * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error + line numbers. + * testsuite/20_util/shared_ptr/cons/43820.cc: Likewise. + + * include/bits/unique_ptr.h (unique_ptr<>::unique_ptr(auto_ptr<>&&)): + Add. + * include/std/memory: Adjust includes order. + * testsuite/20_util/unique_ptr/cons/auto_ptr.cc: New. + * testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc: Likewise. + * testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc: Minor tweaks. + +2010-08-10 Paolo Carlini <paolo.carlini@oracle.com> + PR libstdc++/45228 * include/std/tuple (tuple<typename... _Elements>): Constrain converting constructors and assignment operators with diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 4f87dd4..fe79cdd 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -206,8 +206,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) * @param __r A %shared_ptr. * @post get() == __r.get() && use_count() == __r.use_count() */ - template<typename _Tp1> - shared_ptr(const shared_ptr<_Tp1>& __r) : __shared_ptr<_Tp>(__r) { } + template<typename _Tp1, typename = typename + std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> + shared_ptr(const shared_ptr<_Tp1>& __r) + : __shared_ptr<_Tp>(__r) { } /** * @brief Move-constructs a %shared_ptr instance from @a __r. @@ -222,7 +224,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) * @param __r A %shared_ptr rvalue. * @post *this contains the old value of @a __r, @a __r is empty. */ - template<typename _Tp1> + template<typename _Tp1, typename = typename + std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> shared_ptr(shared_ptr<_Tp1>&& __r) : __shared_ptr<_Tp>(std::move(__r)) { } @@ -366,11 +369,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) public: weak_ptr() : __weak_ptr<_Tp>() { } - template<typename _Tp1> + template<typename _Tp1, typename = typename + std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> weak_ptr(const weak_ptr<_Tp1>& __r) : __weak_ptr<_Tp>(__r) { } - template<typename _Tp1> + template<typename _Tp1, typename = typename + std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> weak_ptr(const shared_ptr<_Tp1>& __r) : __weak_ptr<_Tp>(__r) { } diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 0a69d2b..b9b0ed9 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -601,7 +601,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // generated copy constructor, assignment, destructor are fine. - template<typename _Tp1> + template<typename _Tp1, typename = typename + std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r) : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) } @@ -613,7 +614,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __r._M_ptr = 0; } - template<typename _Tp1> + template<typename _Tp1, typename = typename + std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> __shared_ptr(__shared_ptr<_Tp1, _Lp>&& __r) : _M_ptr(__r._M_ptr), _M_refcount() // never throws { @@ -965,7 +967,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // // It is not possible to avoid spurious access violations since // in multithreaded programs __r._M_ptr may be invalidated at any point. - template<typename _Tp1> + template<typename _Tp1, typename = typename + std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r) : _M_refcount(__r._M_refcount) // never throws { @@ -973,7 +976,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _M_ptr = __r.lock().get(); } - template<typename _Tp1> + template<typename _Tp1, typename = typename + std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> __weak_ptr(const __shared_ptr<_Tp1, _Lp>& __r) : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) } diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index ac62ff7..cf05ec2 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -49,7 +49,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { default_delete() { } - template<typename _Up> + template<typename _Up, typename = typename + std::enable_if<std::is_convertible<_Up*, _Tp*>::value>::type> default_delete(const default_delete<_Up>&) { } void @@ -133,14 +134,32 @@ _GLIBCXX_BEGIN_NAMESPACE(std) unique_ptr(unique_ptr&& __u) : _M_t(__u.release(), std::forward<deleter_type>(__u.get_deleter())) { } - template<typename _Up, typename _Up_Deleter> + template<typename _Up, typename _Up_Deleter, typename = typename + std::enable_if + <std::is_convertible<typename unique_ptr<_Up, _Up_Deleter>::pointer, + pointer>::value + && !std::is_array<_Up>::value + && ((std::is_reference<_Tp_Deleter>::value + && std::is_same<_Up_Deleter, _Tp_Deleter>::value) + || (!std::is_reference<_Tp_Deleter>::value + && std::is_convertible<_Up_Deleter, _Tp_Deleter>::value))> + ::type> unique_ptr(unique_ptr<_Up, _Up_Deleter>&& __u) : _M_t(__u.release(), std::forward<deleter_type>(__u.get_deleter())) { } +#if _GLIBCXX_DEPRECATED + template<typename _Up, typename = typename + std::enable_if<std::is_convertible<_Up*, _Tp*>::value + && std::is_same<_Tp_Deleter, + default_delete<_Tp>>::value>::type> + unique_ptr(auto_ptr<_Up>&& __u) + : _M_t(__u.release(), deleter_type()) { } +#endif + // Destructor. ~unique_ptr() { reset(); } - + // Assignment. unique_ptr& operator=(unique_ptr&& __u) @@ -150,7 +169,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return *this; } - template<typename _Up, typename _Up_Deleter> + template<typename _Up, typename _Up_Deleter, typename = typename + std::enable_if + <std::is_convertible<typename unique_ptr<_Up, _Up_Deleter>::pointer, + pointer>::value + && !std::is_array<_Up>::value>::type> unique_ptr& operator=(unique_ptr<_Up, _Up_Deleter>&& __u) { diff --git a/libstdc++-v3/include/std/memory b/libstdc++-v3/include/std/memory index 3e7d4e84..42e948a 100644 --- a/libstdc++-v3/include/std/memory +++ b/libstdc++-v3/include/std/memory @@ -1,6 +1,7 @@ // <memory> -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, +// 2009, 2010 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -81,10 +82,10 @@ # include <type_traits> # include <functional> # include <debug/debug.h> -# include <bits/unique_ptr.h> # if _GLIBCXX_DEPRECATED # include <backward/auto_ptr.h> # endif +# include <bits/unique_ptr.h> # if defined(_GLIBCXX_INCLUDE_AS_CXX0X) # include <tr1_impl/boost_sp_counted_base.h> # else diff --git a/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc index eee2644..252265c 100644 --- a/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc +++ b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc @@ -2,7 +2,7 @@ // { dg-options "-std=gnu++0x" } // { dg-require-cstdint "" } -// Copyright (C) 2008, 2009 Free Software Foundation +// Copyright (C) 2008, 2009, 2010 Free Software Foundation // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -24,26 +24,26 @@ void test01() { - std::ratio<INTMAX_MAX, INTMAX_MAX> r1; - std::ratio<-INTMAX_MAX, INTMAX_MAX> r2; + std::ratio<INTMAX_MAX, INTMAX_MAX> r1 __attribute__((unused)); + std::ratio<-INTMAX_MAX, INTMAX_MAX> r2 __attribute__((unused)); } void test02() { - std::ratio<INTMAX_MIN, 1> r1; + std::ratio<INTMAX_MIN, 1> r1 __attribute__((unused)); } void test03() { - std::ratio<1, INTMAX_MIN> r1; + std::ratio<1, INTMAX_MIN> r1 __attribute__((unused)); } void test04() { - std::ratio<1,0> r1; + std::ratio<1,0> r1 __attribute__((unused)); } // { dg-error "instantiated from here" "" { target *-*-* } 34 } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820.cc index 09be153..81d3a0f 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820.cc @@ -35,6 +35,6 @@ void test01() // { dg-error "incomplete" "" { target *-*-* } 566 } std::shared_ptr<X> p9(ap()); // { dg-error "here" } - // { dg-error "incomplete" "" { target *-*-* } 657 } + // { dg-error "incomplete" "" { target *-*-* } 659 } } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc index e2ef60e..b078a7d 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc @@ -21,28 +21,16 @@ // 20.6.6.2 Template class shared_ptr [util.smartptr.shared] #include <memory> -#include <testsuite_hooks.h> struct A { }; // 20.6.6.2.3 shared_ptr assignment [util.smartptr.shared.const] // Construction from const auto_ptr -int +void test01() { - bool test __attribute__((unused)) = true; - const std::auto_ptr<A> a; std::shared_ptr<A> p(std::move(a)); // { dg-error "no match" } - - return 0; -} - -int -main() -{ - test01(); - return 0; } // { dg-excess-errors "candidates are" } diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr.cc new file mode 100644 index 0000000..f4b9838 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 20.9.10 Class template unique_ptr [unique.ptr] + +#include <memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 20.9.10.2.1 unique_ptr constructors [unique.ptr.single.ctor] + +// Construction from auto_ptr +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::auto_ptr<A> a(new A); + std::unique_ptr<A> a2(std::move(a)); + VERIFY( a.get() == nullptr ); + VERIFY( a2.get() != 0 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc new file mode 100644 index 0000000..76910c3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/auto_ptr_neg.cc @@ -0,0 +1,36 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2010 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 20.9.10 Class template unique_ptr [unique.ptr] + +#include <memory> + +struct A { }; + +// 20.9.10.2.1 unique_ptr constructors [unique.ptr.single.ctor] + +// Construction from const auto_ptr +void +test01() +{ + const std::auto_ptr<A> a(new A); + std::unique_ptr<A> a2(std::move(a)); // { dg-error "no match" } +} +// { dg-excess-errors "candidates are" } diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc index 7942c05..2635a33 100644 --- a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc @@ -41,9 +41,9 @@ main() return 0; } -// { dg-warning "note" "" { target *-*-* } 324 } -// { dg-warning "note" "" { target *-*-* } 423 } -// { dg-warning "note" "" { target *-*-* } 862 } +// { dg-warning "note" "" { target *-*-* } 327 } +// { dg-warning "note" "" { target *-*-* } 446 } +// { dg-warning "note" "" { target *-*-* } 864 } // { dg-warning "note" "" { target *-*-* } 580 } // { dg-warning "note" "" { target *-*-* } 1027 } // { dg-warning "note" "" { target *-*-* } 340 } |