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
This commit is contained in:
Paolo Carlini 2005-11-12 00:19:24 +00:00 committed by Paolo Carlini
parent 02b3514c84
commit 516ebd4486
6 changed files with 169 additions and 41 deletions

View File

@ -1,3 +1,20 @@
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

View File

@ -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);
};

View File

@ -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; }

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}