This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
PATCH: Fix typedefs-1.cc on ARM
- From: mitchell at codesourcery dot com (Mark Mitchell)
- To: libstdc++ at gcc dot gnu dot org
- Date: Fri, 29 Aug 2008 22:21:43 -0700 (PDT)
- Subject: PATCH: Fix typedefs-1.cc on ARM
- Reply-to: mark at codesourcery dot com
The test in testsuite/20_util/make_signed/typedefs-1.cc was failing on
ARM. The reason is that on that platform (and on any platform, when
-fshort-enums is in use), enums may have size 1, contradicting this
comment:
- // GNU enums start with sizeof short.
- typedef unsigned short __smallest;
This patch fixes the logic in __make_{un,}signed_selector to allow for
this case. The change to type_traits also necessitates moving the
line markers in typedefs_neg.cc.
Finally, typedefs-2.cc then begins to fail, as it expects:
enum test_enum { first_selection };
to be the same size as "short". In other words, typedefs-2.cc is
bogus as it stands; it expects that with -fshort-enums such an enum
has "short" as its underlying type, but that is incorrect. The test
only passed because the logic in type_traits was incorrect.
I chose to fix this by ensuring that the enum does indeed require a
short as the underlying type. The other fix would be to make the test
expect the size to be that of char, but it seemed more interesting to
pick a type that was in the middle of the range of possibilities.
OK to apply?
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
2008-08-29 Mark Mitchell <mark@codesourcery.com>
* include/std/type_traits (__make_unsigned_selector<>): Consider
enums of size smaller than short.
(__make_signed_selector<>): Likewise.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
Adjust line numbers.
* testsuite/20_util/make_usigned/requirements/typedefs_neg.cc:
Adjust line numbers.
* testsuite/20_util/make_signed/requirements/typedefs-2.cc:
Ensure test_enum is the same size as short.
* testsuite/20_util/make_unsigned/requirements/typedefs-2.cc:
Ensure test_enum is the same size as short.
Index: include/std/type_traits
===================================================================
--- include/std/type_traits (revision 139739)
+++ include/std/type_traits (working copy)
@@ -455,15 +455,17 @@ namespace std
struct __make_unsigned_selector<_Tp, false, true>
{
private:
- // GNU enums start with sizeof short.
- typedef unsigned short __smallest;
- static const bool __b1 = sizeof(_Tp) <= sizeof(__smallest);
+ typedef unsigned char __smallest;
+ static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
+ static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
- typedef conditional<__b2, unsigned int, unsigned long> __cond;
- typedef typename __cond::type __cond_type;
+ typedef conditional<__b2, unsigned int, unsigned long> __cond2;
+ typedef typename __cond2::type __cond2_type;
+ typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
+ typedef typename __cond1::type __cond1_type;
public:
- typedef typename conditional<__b1, __smallest, __cond_type>::type __type;
+ typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
};
// Given an integral/enum type, return the corresponding unsigned
@@ -530,15 +532,17 @@ namespace std
struct __make_signed_selector<_Tp, false, true>
{
private:
- // GNU enums start with sizeof short.
- typedef signed short __smallest;
- static const bool __b1 = sizeof(_Tp) <= sizeof(__smallest);
+ typedef signed char __smallest;
+ static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
+ static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
- typedef conditional<__b2, signed int, signed long> __cond;
- typedef typename __cond::type __cond_type;
+ typedef conditional<__b2, signed int, signed long> __cond2;
+ typedef typename __cond2::type __cond2_type;
+ typedef conditional<__b1, signed short, __cond2_type> __cond1;
+ typedef typename __cond1::type __cond1_type;
public:
- typedef typename conditional<__b1, __smallest, __cond_type>::type __type;
+ typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
};
// Given an integral/enum type, return the corresponding signed
Index: testsuite/20_util/make_signed/requirements/typedefs_neg.cc
===================================================================
--- testsuite/20_util/make_signed/requirements/typedefs_neg.cc (revision 139739)
+++ testsuite/20_util/make_signed/requirements/typedefs_neg.cc (working copy)
@@ -49,8 +49,8 @@ void test01()
// { dg-error "instantiated from here" "" { target *-*-* } 41 }
// { dg-error "instantiated from here" "" { target *-*-* } 43 }
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 549 }
-// { dg-error "declaration of" "" { target *-*-* } 515 }
+// { dg-error "invalid use of incomplete type" "" { target *-*-* } 553 }
+// { dg-error "declaration of" "" { target *-*-* } 517 }
// { dg-excess-errors "At global scope" }
// { dg-excess-errors "In instantiation of" }
Index: testsuite/20_util/make_signed/requirements/typedefs-2.cc
===================================================================
--- testsuite/20_util/make_signed/requirements/typedefs-2.cc (revision 139739)
+++ testsuite/20_util/make_signed/requirements/typedefs-2.cc (working copy)
@@ -24,7 +24,7 @@
#include <type_traits>
#include <testsuite_hooks.h>
-enum test_enum { first_selection };
+enum test_enum { first_selection = ((unsigned char)-1) + 1 };
void test01()
{
Index: testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
===================================================================
--- testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc (revision 139739)
+++ testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc (working copy)
@@ -49,7 +49,7 @@ void test01()
// { dg-error "instantiated from here" "" { target *-*-* } 41 }
// { dg-error "instantiated from here" "" { target *-*-* } 43 }
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 474 }
+// { dg-error "invalid use of incomplete type" "" { target *-*-* } 476 }
// { dg-error "declaration of" "" { target *-*-* } 440 }
// { dg-excess-errors "At global scope" }
Index: testsuite/20_util/make_unsigned/requirements/typedefs-2.cc
===================================================================
--- testsuite/20_util/make_unsigned/requirements/typedefs-2.cc (revision 139739)
+++ testsuite/20_util/make_unsigned/requirements/typedefs-2.cc (working copy)
@@ -24,7 +24,7 @@
#include <type_traits>
#include <testsuite_hooks.h>
-enum test_enum { first_selection };
+enum test_enum { first_selection = ((unsigned char)-1) + 1 };
void test01()
{