diff options
author | Paolo Carlini <pcarlini@suse.de> | 2005-11-12 00:19:24 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2005-11-12 00:19:24 +0000 |
commit | 516ebd44865ef872178e6003100d241d3dd39237 (patch) | |
tree | 1e4c129574445fd3ec42abdb00758ec44217ca2b | |
parent | 02b3514c846f40f04ee6c0a271ba7b1f5de2c246 (diff) | |
download | gcc-516ebd44865ef872178e6003100d241d3dd39237.zip gcc-516ebd44865ef872178e6003100d241d3dd39237.tar.gz gcc-516ebd44865ef872178e6003100d241d3dd39237.tar.bz2 |
re PR libstdc++/24808 (is_object fails to compile with incomplete types)
2005-11-11 Paolo Carlini <pcarlini@suse.de>
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
6 files changed, 169 insertions, 41 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7e7f137..1d812cc 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,22 @@ 2005-11-11 Paolo Carlini <pcarlini@suse.de> + 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 <pcarlini@suse.de> + PR libstdc++/24799 * include/tr1/functional (hash): Inherit from std::unary_function. * testsuite/tr1/6_containers/unordered/hash/24799.cc: New. diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index c89bb8e..70f3316 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<typename _From, typename _To> - struct __conv_helper + template<typename _Tp> + struct __in_array : public __sfinae_types { private: - static __one __test(_To); - static __two __test(...); - static _From __makeFrom(); + template<typename _Up> + static __one __test(_Up(*)[1]); + template<typename> + 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<typename> struct is_class { }; - template<typename _Tp, bool = (is_void<_Tp>::value - || is_reference<_Tp>::value)> - struct __is_function_helper - { - static const bool __value = (__conv_helper<typename - add_reference<_Tp>::type, typename - add_pointer<_Tp>::type>::__value); - }; - - template<typename _Tp> - struct __is_function_helper<_Tp, true> - { static const bool __value = false; }; - template<typename _Tp> struct is_function - : public integral_constant<bool, __is_function_helper<_Tp>::__value> + : public integral_constant<bool, !(__in_array<_Tp>::__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<typename _Tp, bool = !is_object<_Tp>::value> - struct __is_abstract_helper - : public __sfinae_types - { - private: - template<typename> - static __one __test(...); - template<typename _Up> - static __two __test(_Up(*)[1]); - - public: - static const bool __value = sizeof(__test<_Tp>(0)) == 1; - }; - - template<typename _Tp> - struct __is_abstract_helper<_Tp, true> - { static const bool __value = false; }; - template<typename _Tp> struct is_abstract - : public integral_constant<bool, __is_abstract_helper<_Tp>::__value> { }; + : public integral_constant<bool, (!__in_array<_Tp>::__value + && __is_union_or_class<_Tp>::value)> { }; template<typename _Tp> struct has_trivial_constructor @@ -490,6 +464,19 @@ namespace tr1 __is_base_of_helper<_Base, _Derived>::__value> { }; + template<typename _From, typename _To> + 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<typename _Tp> 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<typename + static const bool __value = (__is_convertible_simple<typename add_reference<_From>::type, _To>::__value); }; diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h index ec5630b..e925c84 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 0000000..70ba016 --- /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 <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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 4.5.2 Composite type traits + +#include <tr1/type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +// libstdc++/24808 +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_object; + using namespace __gnu_test; + + VERIFY( (test_category<is_object, IncompleteClass>(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 0000000..88a3cdc --- /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 <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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 4.5.1 Primary type categories + +#include <tr1/type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +// libstdc++/24808 +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_enum; + using namespace __gnu_test; + + VERIFY( (test_category<is_enum, IncompleteClass>(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 0000000..6ba9969 --- /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 <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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 4.5.1 Primary type categories + +#include <tr1/type_traits> +#include <testsuite_hooks.h> +#include <testsuite_tr1.h> + +// libstdc++/24808 +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_function; + using namespace __gnu_test; + + VERIFY( (test_category<is_function, IncompleteClass>(false)) ); +} + +int main() +{ + test01(); + return 0; +} |