Makefile.am: Add ext/aligned_buffer.h
authorJonathan Wakely <jwakely.gcc@gmail.com>
Sun, 7 Apr 2013 16:44:40 +0000 (16:44 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Sun, 7 Apr 2013 16:44:40 +0000 (17:44 +0100)
* include/Makefile.am: Add ext/aligned_buffer.h
* include/Makefile.in: Regenerate.
* include/ext/aligned_buffer.h: New.
* include/std/future (_Result): Use __aligned_buffer.
* include/bits/forward_list.h (_Fwd_list_node): Likewise.
* include/bits/shared_ptr_base.h (_Sp_counted_ptr_inplace): Likewise.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error line
number.

From-SVN: r197554

libstdc++-v3/ChangeLog
libstdc++-v3/include/Makefile.am
libstdc++-v3/include/Makefile.in
libstdc++-v3/include/bits/forward_list.h
libstdc++-v3/include/bits/shared_ptr_base.h
libstdc++-v3/include/ext/aligned_buffer.h [new file with mode: 0644]
libstdc++-v3/include/std/future
libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc

index fd0d09c2292623f1212821408adf549c22e34bca..0dfa2f92cc24b7d7e08763f37ea0ed2adcd837a5 100644 (file)
@@ -1,3 +1,14 @@
+2013-04-07  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       * include/Makefile.am: Add ext/aligned_buffer.h
+       * include/Makefile.in: Regenerate.
+       * include/ext/aligned_buffer.h: New.
+       * include/std/future (_Result): Use __aligned_buffer.
+       * include/bits/forward_list.h (_Fwd_list_node): Likewise.
+       * include/bits/shared_ptr_base.h (_Sp_counted_ptr_inplace): Likewise.
+       * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error line
+       number.
+
 2013-04-07  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
        * include/bits/forward_list.h: Only include required headers.
index 6bd3b438065b6369c93f69fb06f1340ad65e51aa..b0ea41d7d714bb42262e9dc350f184a65b658845 100644 (file)
@@ -495,6 +495,7 @@ ext_srcdir = ${glibcxx_srcdir}/include/ext
 ext_builddir = ./ext
 ext_headers = \
        ${ext_srcdir}/algorithm \
+       ${ext_srcdir}/aligned_buffer.h \
        ${ext_srcdir}/alloc_traits.h \
        ${ext_srcdir}/atomicity.h \
        ${ext_srcdir}/array_allocator.h \
index 6e3c89453562f8ddab3e22d607946cfba3da2751..a644155422c1b92442757510617a77f77bced265 100644 (file)
@@ -755,6 +755,7 @@ ext_srcdir = ${glibcxx_srcdir}/include/ext
 ext_builddir = ./ext
 ext_headers = \
        ${ext_srcdir}/algorithm \
+       ${ext_srcdir}/aligned_buffer.h \
        ${ext_srcdir}/alloc_traits.h \
        ${ext_srcdir}/atomicity.h \
        ${ext_srcdir}/array_allocator.h \
index 8270c4e7f65ffc6f53416ccb8b531234a2ccf3d8..e7c4bdd816eccb9d169c9309589bbefd4c2661b5 100644 (file)
@@ -39,6 +39,7 @@
 #include <bits/stl_function.h>
 #include <bits/allocator.h>
 #include <ext/alloc_traits.h>
+#include <ext/aligned_buffer.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -99,20 +100,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
     {
       _Fwd_list_node() = default;
 
-      typename aligned_storage<sizeof(_Tp), alignment_of<_Tp>::value>::type
-       _M_storage;
+      __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
 
       _Tp*
       _M_valptr() noexcept
-      {
-       return static_cast<_Tp*>(static_cast<void*>(&_M_storage));
-      }
+      { return _M_storage._M_ptr(); }
 
       const _Tp*
       _M_valptr() const noexcept
-      {
-       return static_cast<const _Tp*>(static_cast<const void*>(&_M_storage));
-      }
+      { return _M_storage._M_ptr(); }
     };
 
   /**
index c5df1fbcacceca867dff53d61187a7d1eadac76a..f46364500bc9f94b801945bf3fb5a25652f33af6 100644 (file)
@@ -49,6 +49,8 @@
 #ifndef _SHARED_PTR_BASE_H
 #define _SHARED_PTR_BASE_H 1
 
+#include <ext/aligned_buffer.h>
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -393,7 +395,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        _Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args)
        : _M_impl(__a), _M_storage()
        {
-         _M_impl._M_ptr = static_cast<_Tp*>(static_cast<void*>(&_M_storage));
+         _M_impl._M_ptr = _M_storage._M_ptr();
          // _GLIBCXX_RESOLVE_LIB_DEFECTS
          // 2070.  allocate_shared should use allocator_traits<A>::construct
          allocator_traits<_Alloc>::construct(__a, _M_impl._M_ptr,
@@ -422,9 +424,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _M_get_deleter(const std::type_info& __ti) noexcept
       {
 #ifdef __GXX_RTTI
-       return __ti == typeid(_Sp_make_shared_tag)
-              ? static_cast<void*>(&_M_storage)
-              : 0;
+       return __ti == typeid(_Sp_make_shared_tag) ? _M_storage._M_addr() : 0;
 #else
         return 0;
 #endif
@@ -432,8 +432,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
     private:
       _Impl _M_impl;
-      typename aligned_storage<sizeof(_Tp), alignment_of<_Tp>::value>::type
-       _M_storage;
+      __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
     };
 
   template<_Lock_policy _Lp>
diff --git a/libstdc++-v3/include/ext/aligned_buffer.h b/libstdc++-v3/include/ext/aligned_buffer.h
new file mode 100644 (file)
index 0000000..ffed88c
--- /dev/null
@@ -0,0 +1,73 @@
+// Aligned memory buffer -*- C++ -*-
+
+// Copyright (C) 2013 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
+// 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file ext/aligned_buffer.h
+ *  This file is a GNU extension to the Standard C++ Library.
+ */
+
+#ifndef _ALIGNED_BUFFER_H
+#define _ALIGNED_BUFFER_H 1
+
+#pragma GCC system_header
+
+#if __cplusplus >= 201103L
+# include <type_traits>
+#else
+# include <bits/c++0x_warning.h>
+#endif
+
+namespace __gnu_cxx
+{
+  template<typename _Tp>
+    struct __aligned_buffer
+    : std::aligned_storage<sizeof(_Tp), std::alignment_of<_Tp>::value>
+    {
+      typename
+       std::aligned_storage<sizeof(_Tp), std::alignment_of<_Tp>::value>::type
+       _M_storage;
+
+      void*
+      _M_addr() noexcept
+      {
+        return static_cast<void*>(&_M_storage);
+      }
+
+      const void*
+      _M_addr() const noexcept
+      {
+        return static_cast<const void*>(&_M_storage);
+      }
+
+      _Tp*
+      _M_ptr() noexcept
+      { return static_cast<_Tp*>(_M_addr()); }
+
+      const _Tp*
+      _M_ptr() const noexcept
+      { return static_cast<const _Tp*>(_M_addr()); }
+    };
+
+} // namespace
+
+#endif /* _ALIGNED_BUFFER_H */
index 30100fe05e488dfc211462d3110c4f03492ba497..a86a7ca1ee04d1ef7332899aa5e3d71343ed117e 100644 (file)
@@ -46,6 +46,7 @@
 #include <bits/shared_ptr.h>
 #include <bits/uses_allocator.h>
 #include <bits/alloc_traits.h>
+#include <ext/aligned_buffer.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -206,12 +207,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       struct _Result : _Result_base
       {
       private:
-       typedef alignment_of<_Res>                              __a_of;
-       typedef aligned_storage<sizeof(_Res), __a_of::value>    __align_storage;
-       typedef typename __align_storage::type                  __align_type;
-
-       __align_type            _M_storage;
-       bool                    _M_initialized;
+       __gnu_cxx::__aligned_buffer<_Res>       _M_storage;
+       bool                                    _M_initialized;
 
       public:
        typedef _Res result_type;
@@ -226,26 +223,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
        // Return lvalue, future will add const or rvalue-reference
        _Res&
-       _M_value() noexcept { return *static_cast<_Res*>(_M_addr()); }
+       _M_value() noexcept { return *_M_storage._M_ptr(); }
 
        void
        _M_set(const _Res& __res)
        {
-         ::new (_M_addr()) _Res(__res);
+         ::new (_M_storage._M_addr()) _Res(__res);
          _M_initialized = true;
        }
 
        void
        _M_set(_Res&& __res)
        {
-         ::new (_M_addr()) _Res(std::move(__res));
+         ::new (_M_storage._M_addr()) _Res(std::move(__res));
          _M_initialized = true;
        }
 
       private:
        void _M_destroy() { delete this; }
-
-       void* _M_addr() noexcept { return static_cast<void*>(&_M_storage); }
     };
 
     /// A unique_ptr based on the instantiating type.
index 6fa34a9543b84c2744fbbcef44269ac692d9f667..3a5f0539a59c128018106266dd029683a26fc6b4 100644 (file)
@@ -32,7 +32,7 @@ void test01()
 {
   X* px = 0;
   std::shared_ptr<X> p1(px);   // { dg-error "here" }
-  // { dg-error "incomplete" "" { target *-*-* } 771 }
+  // { dg-error "incomplete" "" { target *-*-* } 770 }
 
   std::shared_ptr<X> p9(ap());  // { dg-error "here" }
   // { dg-error "incomplete" "" { target *-*-* } 307 }