* [PATCH] g++.dg/cpp1y/pr58708.C wchar_t size
@ 2015-11-17 16:04 David Edelsohn
2015-11-17 16:22 ` Jonathan Wakely
0 siblings, 1 reply; 4+ messages in thread
From: David Edelsohn @ 2015-11-17 16:04 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: GCC Patches
The testcase in the GCC testsuite assumes that wchar_t is 32 bits,
which is not correct on AIX. 32 bit AIX maintains 16 bit wchar_t for
backward compatibility (64 bit AIX uses 32 bit wchar_t).
What is the preferred method to make the testcase safe for smaller wchar_t?
The following patch works for me. I wasn't sure what header file and
what macro test would be considered portable. I could include
stdint.h and compare
WCHAR_MAX == UINT16_MAX
or
WCHAR_MAX < UINT32_MAX
Thanks, David
Index: pr58708.C
===================================================================
--- pr58708.C (revision 230463)
+++ pr58708.C (working copy)
@@ -1,5 +1,7 @@
// { dg-do run { target c++14 } }
+#include <wchar.h>
+
template<typename, typename>
struct is_same
{
@@ -43,7 +45,11 @@
if (foo.chars[1] != 98) __builtin_abort();
if (foo.chars[2] != 99) __builtin_abort();
- auto wfoo = L"\x01020304\x05060708"_foo;
+#if WCHAR_MAX == 65535
+ auto wfoo = L"\x0102\x0304"_foo;
+#else
+ auto wfoo = L"\x01020304\x05060708"_foo;
+#endif
if (is_same<decltype(wfoo)::char_type, wchar_t>::value != true)
__builtin_abort();
if (sizeof(wfoo.chars)/sizeof(wchar_t) != 2) __builtin_abort();
if (wfoo.chars[0] != 16909060) __builtin_abort();
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] g++.dg/cpp1y/pr58708.C wchar_t size
2015-11-17 16:04 [PATCH] g++.dg/cpp1y/pr58708.C wchar_t size David Edelsohn
@ 2015-11-17 16:22 ` Jonathan Wakely
2015-11-17 16:50 ` David Edelsohn
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2015-11-17 16:22 UTC (permalink / raw)
To: David Edelsohn; +Cc: GCC Patches
On 17 November 2015 at 16:04, David Edelsohn wrote:
> The testcase in the GCC testsuite assumes that wchar_t is 32 bits,
> which is not correct on AIX. 32 bit AIX maintains 16 bit wchar_t for
> backward compatibility (64 bit AIX uses 32 bit wchar_t).
>
> What is the preferred method to make the testcase safe for smaller wchar_t?
>
> The following patch works for me. I wasn't sure what header file and
> what macro test would be considered portable. I could include
> stdint.h and compare
>
> WCHAR_MAX == UINT16_MAX
>
> or
>
> WCHAR_MAX < UINT32_MAX
__SIZEOF_WCHAR_T__ is always pre-defined by the compiler, so that
could be used.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] g++.dg/cpp1y/pr58708.C wchar_t size
2015-11-17 16:22 ` Jonathan Wakely
@ 2015-11-17 16:50 ` David Edelsohn
2015-11-17 23:41 ` Mike Stump
0 siblings, 1 reply; 4+ messages in thread
From: David Edelsohn @ 2015-11-17 16:50 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: GCC Patches
On Tue, Nov 17, 2015 at 11:22 AM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 17 November 2015 at 16:04, David Edelsohn wrote:
>> The testcase in the GCC testsuite assumes that wchar_t is 32 bits,
>> which is not correct on AIX. 32 bit AIX maintains 16 bit wchar_t for
>> backward compatibility (64 bit AIX uses 32 bit wchar_t).
>>
>> What is the preferred method to make the testcase safe for smaller wchar_t?
>>
>> The following patch works for me. I wasn't sure what header file and
>> what macro test would be considered portable. I could include
>> stdint.h and compare
>>
>> WCHAR_MAX == UINT16_MAX
>>
>> or
>>
>> WCHAR_MAX < UINT32_MAX
>
> __SIZEOF_WCHAR_T__ is always pre-defined by the compiler, so that
> could be used.
Thanks for the pointer. How about the following?
Thanks, David
Index: pr58708.C
===================================================================
--- pr58708.C (revision 230463)
+++ pr58708.C (working copy)
@@ -43,7 +43,11 @@
if (foo.chars[1] != 98) __builtin_abort();
if (foo.chars[2] != 99) __builtin_abort();
- auto wfoo = L"\x01020304\x05060708"_foo;
+#if __SIZEOF_WCHAR_T__ == 2
+ auto wfoo = L"\x0102\x0304"_foo;
+#else
+ auto wfoo = L"\x01020304\x05060708"_foo;
+#endif
if (is_same<decltype(wfoo)::char_type, wchar_t>::value != true)
__builtin_abort();
if (sizeof(wfoo.chars)/sizeof(wchar_t) != 2) __builtin_abort();
if (wfoo.chars[0] != 16909060) __builtin_abort();
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] g++.dg/cpp1y/pr58708.C wchar_t size
2015-11-17 16:50 ` David Edelsohn
@ 2015-11-17 23:41 ` Mike Stump
0 siblings, 0 replies; 4+ messages in thread
From: Mike Stump @ 2015-11-17 23:41 UTC (permalink / raw)
To: David Edelsohn; +Cc: Jonathan Wakely, GCC Patches
On Nov 17, 2015, at 8:50 AM, David Edelsohn <dje.gcc@gmail.com> wrote:
>
> Thanks for the pointer. How about the following?
Ok.
sizeof (*wfoo) or sizeof (wchar_t) or some such might be even more portable.
>
> Thanks, David
>
>
> Index: pr58708.C
> ===================================================================
> --- pr58708.C (revision 230463)
> +++ pr58708.C (working copy)
> @@ -43,7 +43,11 @@
> if (foo.chars[1] != 98) __builtin_abort();
> if (foo.chars[2] != 99) __builtin_abort();
>
> - auto wfoo = L"\x01020304\x05060708"_foo;
> +#if __SIZEOF_WCHAR_T__ == 2
> + auto wfoo = L"\x0102\x0304"_foo;
> +#else
> + auto wfoo = L"\x01020304\x05060708"_foo;
> +#endif
> if (is_same<decltype(wfoo)::char_type, wchar_t>::value != true)
> __builtin_abort();
> if (sizeof(wfoo.chars)/sizeof(wchar_t) != 2) __builtin_abort();
> if (wfoo.chars[0] != 16909060) __builtin_abort();
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-11-17 23:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17 16:04 [PATCH] g++.dg/cpp1y/pr58708.C wchar_t size David Edelsohn
2015-11-17 16:22 ` Jonathan Wakely
2015-11-17 16:50 ` David Edelsohn
2015-11-17 23:41 ` Mike Stump
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).