From 516ebd44865ef872178e6003100d241d3dd39237 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sat, 12 Nov 2005 00:19:24 +0000 Subject: [PATCH] re PR libstdc++/24808 (is_object fails to compile with incomplete types) 2005-11-11 Paolo Carlini PR libstdc++/24808 * include/tr1/type_traits (__is_abstract_helper): Rename to __in_array (with complemented logic). (is_function): Use it, don't use __conv_helper. (is_abstract): Adjust. (__conv_helper): Rename to __is_convertible_simple. (is_convertible): Adjust. * testsuite/testsuite_tr1.h (class IncompleteClass): Add. * testsuite/tr1/4_metaprogramming/composite_type_traits/is_object/ 24808.cc: New. * testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/ 24808.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/ 24808.cc: Likewise. From-SVN: r106818 --- libstdc++-v3/ChangeLog | 17 +++++ libstdc++-v3/include/tr1/type_traits | 69 ++++++++----------- libstdc++-v3/testsuite/testsuite_tr1.h | 1 + .../composite_type_traits/is_object/24808.cc | 41 +++++++++++ .../primary_type_categories/is_enum/24808.cc | 41 +++++++++++ .../is_function/24808.cc | 41 +++++++++++ 6 files changed, 169 insertions(+), 41 deletions(-) create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_object/24808.cc create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/24808.cc create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/24808.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7e7f137a474e..1d812ccc4754 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,20 @@ +2005-11-11 Paolo Carlini + + PR libstdc++/24808 + * include/tr1/type_traits (__is_abstract_helper): Rename to __in_array + (with complemented logic). + (is_function): Use it, don't use __conv_helper. + (is_abstract): Adjust. + (__conv_helper): Rename to __is_convertible_simple. + (is_convertible): Adjust. + * testsuite/testsuite_tr1.h (class IncompleteClass): Add. + * testsuite/tr1/4_metaprogramming/composite_type_traits/is_object/ + 24808.cc: New. + * testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/ + 24808.cc: Likewise. + * testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/ + 24808.cc: Likewise. + 2005-11-11 Paolo Carlini PR libstdc++/24799 diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index c89bb8eae78c..70f3316a7bc4 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -42,24 +42,25 @@ namespace std { namespace tr1 { - // For use in __conv_helper, is_abstract and elsewhere. + // For use in __in_array and elsewhere. struct __sfinae_types { typedef char __one; typedef struct { char __arr[2]; } __two; }; - template - struct __conv_helper + template + struct __in_array : public __sfinae_types { private: - static __one __test(_To); - static __two __test(...); - static _From __makeFrom(); + template + static __one __test(_Up(*)[1]); + template + static __two __test(...); public: - static const bool __value = sizeof(__test(__makeFrom())) == 1; + static const bool __value = sizeof(__test<_Tp>(0)) == 1; }; #define _DEFINE_SPEC_BODY(_Value) \ @@ -183,22 +184,12 @@ namespace tr1 template struct is_class { }; - template::value - || is_reference<_Tp>::value)> - struct __is_function_helper - { - static const bool __value = (__conv_helper::type, typename - add_pointer<_Tp>::type>::__value); - }; - - template - struct __is_function_helper<_Tp, true> - { static const bool __value = false; }; - template struct is_function - : public integral_constant::__value> + : public integral_constant::__value + || __is_union_or_class<_Tp>::value + || is_reference<_Tp>::value + || is_void<_Tp>::value)> { }; /// @brief composite type traits [4.5.2]. @@ -338,27 +329,10 @@ namespace tr1 { }; // Exploit the resolution DR core/337. - template::value> - struct __is_abstract_helper - : public __sfinae_types - { - private: - template - static __one __test(...); - template - static __two __test(_Up(*)[1]); - - public: - static const bool __value = sizeof(__test<_Tp>(0)) == 1; - }; - - template - struct __is_abstract_helper<_Tp, true> - { static const bool __value = false; }; - template struct is_abstract - : public integral_constant::__value> { }; + : public integral_constant::__value + && __is_union_or_class<_Tp>::value)> { }; template struct has_trivial_constructor @@ -490,6 +464,19 @@ namespace tr1 __is_base_of_helper<_Base, _Derived>::__value> { }; + template + struct __is_convertible_simple + : public __sfinae_types + { + private: + static __one __test(_To); + static __two __test(...); + static _From __makeFrom(); + + public: + static const bool __value = sizeof(__test(__makeFrom())) == 1; + }; + template struct __is_int_or_cref { @@ -510,7 +497,7 @@ namespace tr1 struct __is_convertible_helper { // "An imaginary lvalue of type From...". - static const bool __value = (__conv_helper::type, _To>::__value); }; diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h index ec5630bf409e..e925c84199da 100644 --- a/libstdc++-v3/testsuite/testsuite_tr1.h +++ b/libstdc++-v3/testsuite/testsuite_tr1.h @@ -102,6 +102,7 @@ namespace __gnu_test union UnionType { }; + class IncompleteClass; int truncate_float(float x) { return (int)x; } long truncate_double(double x) { return (long)x; } diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_object/24808.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_object/24808.cc new file mode 100644 index 000000000000..70ba01673880 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_object/24808.cc @@ -0,0 +1,41 @@ +// 2005-11-11 Paolo Carlini +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 4.5.2 Composite type traits + +#include +#include +#include + +// libstdc++/24808 +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_object; + using namespace __gnu_test; + + VERIFY( (test_category(true)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/24808.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/24808.cc new file mode 100644 index 000000000000..88a3cdceda63 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/24808.cc @@ -0,0 +1,41 @@ +// 2005-11-11 Paolo Carlini +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 4.5.1 Primary type categories + +#include +#include +#include + +// libstdc++/24808 +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_enum; + using namespace __gnu_test; + + VERIFY( (test_category(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/24808.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/24808.cc new file mode 100644 index 000000000000..6ba9969a2ee5 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/24808.cc @@ -0,0 +1,41 @@ +// 2005-11-11 Paolo Carlini +// +// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 4.5.1 Primary type categories + +#include +#include +#include + +// libstdc++/24808 +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_function; + using namespace __gnu_test; + + VERIFY( (test_category(false)) ); +} + +int main() +{ + test01(); + return 0; +} -- 2.43.5