2005-01-11 Paolo Carlini <pcarlini@suse.de>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Jan 2005 12:29:31 +0000 (12:29 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Jan 2005 12:29:31 +0000 (12:29 +0000)
* include/tr1/type_traits: Implement alignment_of and aligned_storage.
* testsuite/tr1/4_metaprogramming/other_transformations/
aligned_storage/aligned_storage.cc: New.
* testsuite/tr1/4_metaprogramming/other_transformations/
aligned_storage/typedefs.cc: Likewise.
* testsuite/tr1/4_metaprogramming/type_properties/
alignment_of/alignment_of.cc: Likewise.
* testsuite/tr1/4_metaprogramming/type_properties/
alignment_of/typedefs.cc: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@93183 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/tr1/type_traits
libstdc++-v3/testsuite/tr1/4_metaprogramming/other_transformations/aligned_storage/aligned_storage.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/other_transformations/aligned_storage/typedefs.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/alignment_of/alignment_of.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/alignment_of/typedefs.cc [new file with mode: 0644]

index 7652f5e..bb1599c 100644 (file)
@@ -1,3 +1,15 @@
+2005-01-11  Paolo Carlini  <pcarlini@suse.de>
+
+       * include/tr1/type_traits: Implement alignment_of and aligned_storage.
+       * testsuite/tr1/4_metaprogramming/other_transformations/
+       aligned_storage/aligned_storage.cc: New.
+       * testsuite/tr1/4_metaprogramming/other_transformations/
+       aligned_storage/typedefs.cc: Likewise.
+       * testsuite/tr1/4_metaprogramming/type_properties/
+       alignment_of/alignment_of.cc: Likewise.
+       * testsuite/tr1/4_metaprogramming/type_properties/
+       alignment_of/typedefs.cc: Likewise.
+
 2005-01-10  Paolo Carlini  <pcarlini@suse.de>
 
        * Makefile.in: Regenerate.
index eb1087f..1cb847c 100644 (file)
@@ -1,6 +1,6 @@
 // TR1 type_traits -*- C++ -*-
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 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
@@ -144,10 +144,10 @@ namespace tr1
   // template<typename>
   //   struct is_member_function_pointer
   //   : public false_type { };
-  //   _DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*,
-  //               is_function<_Tp>::value)
-
-  // Ugly, temporary workaround for member functions with up to 15 arguments.
+  // _DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*,
+  //             is_function<_Tp>::value)
+  //
+  // Temporary workaround for member functions with up to 15 arguments:
   template<typename>
     struct __is_mfp_helper
     { static const bool __value = false; };
@@ -516,6 +516,10 @@ namespace tr1
   template<typename>
     struct has_virtual_destructor
     : public false_type { };
+
+  template<typename _Tp>
+    struct alignment_of
+    : public integral_constant<std::size_t, __alignof__(_Tp)> { };
   
   template<typename>
     struct rank
@@ -652,6 +656,77 @@ namespace tr1
     { typedef typename remove_reference<_Tp>::type*     type; };
 
   /// @brief  other transformations [4.8].
+  
+  // Due to c++/19163 and c++/17743, for the time being we cannot use
+  // the correct, neat implementation :-(
+  // 
+  // template<std::size_t _Len, std::size_t _Align>
+  //   struct aligned_storage
+  //   { typedef char type[_Len] __attribute__((aligned(_Align))); }
+  //
+  // Temporary workaround, useful for Align up to 32:
+  template<std::size_t, std::size_t>
+    struct aligned_storage { };
+
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 1>
+    {
+      union type
+      {
+       unsigned char __data[_Len];
+       char __align __attribute__((aligned(1)));
+      };
+    };
+
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 2>
+    {
+      union type
+      {
+       unsigned char __data[_Len];
+       char __align __attribute__((aligned(2)));
+      };
+    };
+
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 4>
+    {
+      union type
+      {
+       unsigned char __data[_Len];
+       char __align __attribute__((aligned(4)));
+      };
+    };
+
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 8>
+    {
+      union type
+      {
+       unsigned char __data[_Len];
+       char __align __attribute__((aligned(8)));
+      };
+    };
+
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 16>
+    {
+      union type
+      {
+       unsigned char __data[_Len];
+       char __align __attribute__((aligned(16)));
+      };
+    };
+  
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 32>
+    {
+      union type
+      {
+       unsigned char __data[_Len];
+       char __align __attribute__((aligned(32)));
+      };
+    };
 
 #undef _DEFINE_SPEC_0_HELPER
 #undef _DEFINE_SPEC_1_HELPER
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/other_transformations/aligned_storage/aligned_storage.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/other_transformations/aligned_storage/aligned_storage.cc
new file mode 100644 (file)
index 0000000..de04f97
--- /dev/null
@@ -0,0 +1,63 @@
+// 2005-01-11  Paolo Carlini  <pcarlini@suse.de>
+//
+// Copyright (C) 2005 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 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 4.8 Other transformations
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using std::tr1::aligned_storage;
+  using std::tr1::alignment_of;
+  using namespace __gnu_test;
+  
+  const std::size_t align_c = alignment_of<char>::value;
+  VERIFY( (sizeof(aligned_storage<4, align_c>::type) >= 4) );
+  VERIFY( (__alignof__(aligned_storage<4, align_c>::type) == align_c) );
+
+  const std::size_t align_s = alignment_of<short>::value;
+  VERIFY( (sizeof(aligned_storage<1, align_s>::type) >= 1) );
+  VERIFY( (__alignof__(aligned_storage<1, align_s>::type) == align_s) );
+
+  const std::size_t align_i = alignment_of<int>::value;
+  VERIFY( (sizeof(aligned_storage<7, align_i>::type) >= 7) );
+  VERIFY( (__alignof__(aligned_storage<7, align_i>::type) == align_i) );
+
+  const std::size_t align_d = alignment_of<double>::value;
+  VERIFY( (sizeof(aligned_storage<2, align_d>::type) >= 2) );
+  VERIFY( (__alignof__(aligned_storage<2, align_d>::type) == align_d) );
+
+  const std::size_t align_ai = alignment_of<int[4]>::value;
+  VERIFY( (sizeof(aligned_storage<20, align_ai>::type) >= 20) );
+  VERIFY( (__alignof__(aligned_storage<20, align_ai>::type) == align_ai) );
+
+  const std::size_t align_ct = alignment_of<ClassType>::value;
+  VERIFY( (sizeof(aligned_storage<11, align_ct>::type) >= 11) );
+  VERIFY( (__alignof__(aligned_storage<11, align_ct>::type) == align_ct) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/other_transformations/aligned_storage/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/other_transformations/aligned_storage/typedefs.cc
new file mode 100644 (file)
index 0000000..d6b42fb
--- /dev/null
@@ -0,0 +1,33 @@
+// 2005-01-11  Paolo Carlini  <pcarlini@suse.de>
+//
+// Copyright (C) 2005 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 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 
+// NB: This file is for testing tr1/type_traits with NO OTHER INCLUDES.
+
+#include <tr1/type_traits>
+
+// { dg-do compile }
+
+void test01()
+{
+  // Check for required typedefs
+  typedef std::tr1::aligned_storage<1, 1>     test_type;
+  typedef test_type::type                     type;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/alignment_of/alignment_of.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/alignment_of/alignment_of.cc
new file mode 100644 (file)
index 0000000..b10fd33
--- /dev/null
@@ -0,0 +1,45 @@
+// 2005-01-11  Paolo Carlini  <pcarlini@suse.de>
+//
+// Copyright (C) 2005 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 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 4.5.3 Type properties
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using std::tr1::alignment_of;
+  using namespace __gnu_test;
+
+  VERIFY( (test_property<alignment_of, char>(__alignof__(char))) );
+  VERIFY( (test_property<alignment_of, short>(__alignof__(short))) );
+  VERIFY( (test_property<alignment_of, int>(__alignof__(int))) );
+  VERIFY( (test_property<alignment_of, double>(__alignof__(double))) );
+  VERIFY( (test_property<alignment_of, int[4]>(__alignof__(int[4]))) );
+  VERIFY( (test_property<alignment_of, ClassType>(__alignof__(ClassType))) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/alignment_of/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/alignment_of/typedefs.cc
new file mode 100644 (file)
index 0000000..01c193a
--- /dev/null
@@ -0,0 +1,36 @@
+// 2005-01-11  Paolo Carlini  <pcarlini@suse.de>
+//
+// Copyright (C) 2005 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 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 
+// NB: This file is for testing tr1/type_traits with NO OTHER INCLUDES.
+
+#include <tr1/type_traits>
+
+// { dg-do compile }
+
+void test01()
+{
+  // Check for required typedefs
+  typedef std::tr1::alignment_of<int>         test_type;
+  typedef test_type::value_type               value_type;
+  typedef test_type::type                     type;
+  typedef test_type::type::value_type         type_value_type;
+  typedef test_type::type::type               type_type;
+}