type_traits (add_reference): Robustify vs reference to void.
authorPaolo Carlini <pcarlini@suse.de>
Fri, 22 Sep 2006 15:54:52 +0000 (15:54 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 22 Sep 2006 15:54:52 +0000 (15:54 +0000)
2006-09-22  Paolo Carlini  <pcarlini@suse.de>

* include/tr1/type_traits (add_reference): Robustify vs
reference to void.
* testsuite/tr1/4_metaprogramming/reference_modifications/
add_reference.cc: Add test.

* include/tr1/memory: include <tr1/type_traits>.
* include/tr1/boost_shared_ptr.h (__shared_ptr<>::operator*):
Use add_reference instead.
* testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/
explicit_instantiation/1.cc: New.
* testsuite/tr1/2_general_utilities/memory/shared_ptr/
explicit_instantiation/1.cc: Likewise.
* testsuite/tr1/2_general_utilities/memory/weak_ptr/
explicit_instantiation/1.cc: Likewise.

* testsuite/util/testsuite_tr1.h: Tweak; avoid empty enum.

* include/tr1/type_traits_fwd.h: Spelling fix.

* include/tr1/boost_shared_ptr.h: Obvious stylistic fixes.

From-SVN: r117147

libstdc++-v3/ChangeLog
libstdc++-v3/include/tr1/boost_shared_ptr.h
libstdc++-v3/include/tr1/memory
libstdc++-v3/include/tr1/type_traits
libstdc++-v3/include/tr1/type_traits_fwd.h
libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/explicit_instantiation/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/explicit_instantiation/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/2_general_utilities/memory/weak_ptr/explicit_instantiation/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc
libstdc++-v3/testsuite/util/testsuite_tr1.h

index b10764c..425349e 100644 (file)
@@ -1,5 +1,28 @@
 2006-09-22  Paolo Carlini  <pcarlini@suse.de>
 
+       * include/tr1/type_traits (add_reference): Robustify vs
+       reference to void.
+       * testsuite/tr1/4_metaprogramming/reference_modifications/
+       add_reference.cc: Add test.
+
+       * include/tr1/memory: include <tr1/type_traits>.
+       * include/tr1/boost_shared_ptr.h (__shared_ptr<>::operator*):
+       Use add_reference instead.
+       * testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/
+       explicit_instantiation/1.cc: New.
+       * testsuite/tr1/2_general_utilities/memory/shared_ptr/
+       explicit_instantiation/1.cc: Likewise.
+       * testsuite/tr1/2_general_utilities/memory/weak_ptr/
+       explicit_instantiation/1.cc: Likewise.
+
+       * testsuite/util/testsuite_tr1.h: Tweak; avoid empty enum.
+
+       * include/tr1/type_traits_fwd.h: Spelling fix.
+
+       * include/tr1/boost_shared_ptr.h: Obvious stylistic fixes.
+
+2006-09-22  Paolo Carlini  <pcarlini@suse.de>
+
        * include/tr1/boost_shared_ptr.h: Trivial formatting fixes.
 
 2006-09-21  Benjamin Kosnik  <bkoz@redhat.com>
index 0363207..4a6dca2 100644 (file)
@@ -90,8 +90,8 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
       typedef _Tp* argument_type;
 
       void
-      operator()(_Tp* p) const
-      { delete p; }
+      operator()(_Tp* __p) const
+      { delete __p; }
     };
 
   // Empty helper class except when the template argument is _S_mutex.
@@ -451,26 +451,6 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
   struct __dynamic_cast_tag { };
   struct __polymorphic_cast_tag { };
 
-  template<class _Tp>
-    struct __shared_ptr_reference
-    { typedef _Tp& __type; };
-
-  template<>
-    struct __shared_ptr_reference<void>
-    { typedef void __type; };
-
-  template<>
-    struct __shared_ptr_reference<void const>
-    { typedef void __type; };
-
-  template<>
-    struct __shared_ptr_reference<void volatile>
-    { typedef void __type; };
-
-  template<>
-    struct __shared_ptr_reference<void const volatile>
-    { typedef void __type; };
-
 
   // Support for enable_shared_from_this.
 
@@ -497,8 +477,6 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
   template<typename _Tp, _Lock_policy _Lp>
     class __shared_ptr
     {
-      typedef typename __shared_ptr_reference<_Tp>::__type _Reference;
-
     public:
       typedef _Tp   element_type;
       
@@ -589,7 +567,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
          // delete r.release() well-formed
          _Tp1 * __tmp = __r.get();
          _M_refcount = shared_count<_Lp>(__r);
-         __enable_shared_from_this_helper( _M_refcount, __tmp, __tmp );
+         __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp );
        }
 
       template<typename _Tp1>
@@ -648,8 +626,8 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
         reset(_Tp1 * __p, _Deleter __d)
         { __shared_ptr(__p, __d).swap(*this); }
 
-      // Error to instantiate if _Tp is [cv-qual] void.
-      _Reference
+      // Allow instantiation when _Tp is [cv-qual] void.
+      typename add_reference<_Tp>::type
       operator*() const // never throws
       {
        _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0);
@@ -806,33 +784,33 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
       // 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>
-        __weak_ptr(const __weak_ptr<_Tp1, _Lp>& r)
-       : _M_refcount(r._M_refcount) // never throws
+        __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
+       : _M_refcount(__r._M_refcount) // never throws
         {
          __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
-           _M_ptr = r.lock().get();
+           _M_ptr = __r.lock().get();
        }
 
       template<typename _Tp1>
-        __weak_ptr(const __shared_ptr<_Tp1, _Lp>& r)
-       : _M_ptr(r._M_ptr), _M_refcount(r._M_refcount) // never throws
+        __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*>) }
 
       template<typename _Tp1>
         __weak_ptr&
-        operator=(const __weak_ptr<_Tp1, _Lp>& r) // never throws
+        operator=(const __weak_ptr<_Tp1, _Lp>& __r) // never throws
         {
-         _M_ptr = r.lock().get();
-         _M_refcount = r._M_refcount;
+         _M_ptr = __r.lock().get();
+         _M_refcount = __r._M_refcount;
          return *this;
        }
       
       template<typename _Tp1>
         __weak_ptr&
-        operator=(const __shared_ptr<_Tp1, _Lp>& r) // never throws
+        operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws
         {
-         _M_ptr = r._M_ptr;
-         _M_refcount = r._M_refcount;
+         _M_ptr = __r._M_ptr;
+         _M_refcount = __r._M_refcount;
          return *this;
        }
 
@@ -975,27 +953,30 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
     class weak_ptr : public __weak_ptr<_Tp>
     {
     public:
-      weak_ptr() : __weak_ptr<_Tp>() { }
+      weak_ptr()
+      : __weak_ptr<_Tp>() { }
       
       template<typename _Tp1>
-        weak_ptr(const __weak_ptr<_Tp1>& r) : __weak_ptr<_Tp>(r) { }
+        weak_ptr(const __weak_ptr<_Tp1>& __r)
+       : __weak_ptr<_Tp>(__r) { }
     
       template<typename _Tp1>
-        weak_ptr(const __shared_ptr<_Tp1>& r) : __weak_ptr<_Tp>(r) { }
+        weak_ptr(const __shared_ptr<_Tp1>& __r)
+       : __weak_ptr<_Tp>(__r) { }
 
       template<typename _Tp1>
         weak_ptr&
-        operator=(const weak_ptr<_Tp1>& r) // never throws
+        operator=(const weak_ptr<_Tp1>& __r) // never throws
         {
-         this->__weak_ptr<_Tp>::operator=(r);
+         this->__weak_ptr<_Tp>::operator=(__r);
          return *this;
        }
 
       template<typename _Tp1>
         weak_ptr&
-        operator=(const shared_ptr<_Tp1>& r) // never throws
+        operator=(const shared_ptr<_Tp1>& __r) // never throws
         {
-         this->__weak_ptr<_Tp>::operator=(r);
+         this->__weak_ptr<_Tp>::operator=(__r);
          return *this;
        }
     };
index 6befb91..94a0477 100644 (file)
@@ -44,6 +44,7 @@
 #include <ext/concurrence.h>
 #include <bits/functexcept.h>
 #include <debug/debug.h>
+#include <tr1/type_traits>  // tr1::add_reference
 
 #include <tr1/boost_shared_ptr.h>
 
index 0f79831..ccbfc60 100644 (file)
@@ -278,7 +278,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
                                      remove_all_extents<_Tp>::type>::value)>
     { };
 
-  // N.B. Without compiler support we cannot tell union from class types,
+  // NB: Without compiler support we cannot tell union from class types,
   // and is_empty and is_polymorphic don't work at all with the former. 
   template<typename _Tp, bool = !__is_union_or_class<_Tp>::value>
     struct __is_empty_helper
@@ -563,16 +563,23 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
   template<typename _Tp>
     struct remove_reference<_Tp&>
     { typedef _Tp     type; };
-  
-  template<typename _Tp>
-    struct add_reference
+
+  // NB: Careful with reference to void.
+  template<typename _Tp, bool = (is_void<_Tp>::value
+                                || is_reference<_Tp>::value)>
+    struct __add_reference_helper
     { typedef _Tp&    type; };
 
   template<typename _Tp>
-    struct add_reference<_Tp&>
-    { typedef _Tp&    type; };
+    struct __add_reference_helper<_Tp, true>
+    { typedef _Tp     type; };
+
+  template<typename _Tp>
+    struct add_reference
+    : public __add_reference_helper<_Tp>
+    { };
 
-  /// @brief  array modififications [4.7.3].
+  /// @brief  array modifications [4.7.3].
   template<typename _Tp>
     struct remove_extent
     { typedef _Tp     type; };
index fded549..f2130b0 100644 (file)
@@ -1,6 +1,6 @@
 // TR1 type_traits -*- C++ -*-
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
 //
 // 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
@@ -202,7 +202,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
   template<typename _Tp>
     struct add_reference;
 
-  /// @brief  array modififications [4.7.3].
+  /// @brief  array modifications [4.7.3].
   template<typename _Tp>
     struct remove_extent;
 
diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/explicit_instantiation/1.cc
new file mode 100644 (file)
index 0000000..b497ebb
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (C) 2006 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// TR1 2.2.5 Template class enable_shared_from_this [tr.util.smartptr.enab]
+
+#include <tr1/memory>
+#include <testsuite_tr1.h>
+
+// { dg-do compile }
+
+using namespace __gnu_test;
+using std::tr1::enable_shared_from_this;
+template class enable_shared_from_this<int>;
+template class enable_shared_from_this<void>;
+template class enable_shared_from_this<ClassType>;
+template class enable_shared_from_this<IncompleteClass>;
diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/explicit_instantiation/1.cc
new file mode 100644 (file)
index 0000000..015e22e
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (C) 2006 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
+
+#include <tr1/memory>
+#include <testsuite_tr1.h>
+
+// { dg-do compile }
+
+using namespace __gnu_test;
+using std::tr1::shared_ptr;
+template class shared_ptr<int>;
+template class shared_ptr<void>;
+template class shared_ptr<ClassType>;
+template class shared_ptr<IncompleteClass>;
diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/weak_ptr/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/weak_ptr/explicit_instantiation/1.cc
new file mode 100644 (file)
index 0000000..6c22459
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (C) 2006 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// TR1 2.2.4 Template class weak_ptr [tr.util.smartptr.weak]
+
+#include <tr1/memory>
+#include <testsuite_tr1.h>
+
+// { dg-do compile }
+
+using namespace __gnu_test;
+using std::tr1::weak_ptr;
+template class weak_ptr<int>;
+template class weak_ptr<void>;
+template class weak_ptr<ClassType>;
+template class weak_ptr<IncompleteClass>;
index 68e4db8..29ad8c3 100644 (file)
@@ -1,6 +1,6 @@
 // 2004-12-08  Paolo Carlini  <pcarlini@suse.de>
 //
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
 //
 // 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
@@ -37,6 +37,9 @@ void test01()
   VERIFY( (is_same<add_reference<int*>::type, int*&>::value) );
   VERIFY( (is_same<add_reference<ClassType&>::type, ClassType&>::value) );
   VERIFY( (is_same<add_reference<ClassType>::type, ClassType&>::value) );
+
+  VERIFY( (is_same<add_reference<void>::type, void>::value) );
+  VERIFY( (is_same<add_reference<const void>::type, const void>::value) );  
 }
 
 int main()
index e478456..b48f1a3 100644 (file)
@@ -95,7 +95,7 @@ namespace __gnu_test
 
   class DerivedType : public ClassType { };
 
-  enum EnumType { };
+  enum EnumType { e0 };
 
   struct ConvType
   { operator int() const; };
@@ -181,7 +181,7 @@ namespace __gnu_test
 
   // For use in 8_c_compatibility.
   template<typename R, typename T>
-    typename __gnu_cxx::__enable_if<std::tr1::is_same<R, T>::value, 
+    typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value, 
                                    bool>::__type
     check_ret_type(T)
     { return true; }