Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-07-01 Thread Mateusz Mikuła
wrong name): > https://sourceforge.net/p/mingw-w64/mailman/message/35770400/ > > > > > > -- Original Message ------ > > Subject: Re: [Mingw-w64-public] [PATCH] stralign: cast > ua_wcschr > and ua_wcsrchr returns to wchar_t * > >

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-06-04 Thread Mateusz Mikuła
chr((PCWSTR)String,Character); >> + if(WSTR_ALIGNED(String)) { >> + cast.constWcharPointer = wcsrchr((PCWSTR)String,Character); >> + return cast.wcharPointer; >> +} >> return (PUWSTR_C)uaw_wcsrchr(String,Character); >>} >> #if defin

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-06-04 Thread Norbert Pfeiler
onstWcharPointer = wcsrchr((PCWSTR)String,Character); > + return cast.wcharPointer; > +} > return (PUWSTR_C)uaw_wcsrchr(String,Character); > } > #if defined(__cplusplus) && defined(_WConst_Return) > -- > 2.12.1 > > > > -- Original Messa

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-06-04 Thread Mateusz Mikuła
Pointer = wcsrchr((PCWSTR)String,Character); + return cast.wcharPointer; +} return (PUWSTR_C)uaw_wcsrchr(String,Character); } #if defined(__cplusplus) && defined(_WConst_Return) -- 2.12.1 ------ Original Message -- Subject: Re: [Mingw-w64-public] [PATCH] stralign: cast

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-07 Thread Liu Hao
On 2017/4/8 1:00, David Grayson wrote: > I did read the top two answers in the link that Norbert posted: > > http://stackoverflow.com/questions/11373203/accessing-inactive-union-member-and-undefined-behavior > > The first answer (from ecatmur) indicates that this kind of conversion with > a union

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-07 Thread Mateusz Mikuła
clang\msys64\mingw64\x86_64-w64-mingw32\include\stralign.h:121:37: error: cannot initialize return object of type 'PUWSTR_C' (aka 'wchar_t *') with an rvalue of type 'const wchar_t *' ... | Regards, Mateusz -- Original Message -- Subject: Re: [Mingw-w64-public] [PATCH] stralign: cast ua_w

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-07 Thread David Grayson
I did read the top two answers in the link that Norbert posted: http://stackoverflow.com/questions/11373203/accessing-inactive-union-member-and-undefined-behavior The first answer (from ecatmur) indicates that this kind of conversion with a union would be undefined behavior in C++, but not C.

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-07 Thread Kai Tietz
2017-04-07 17:21 GMT+02:00 David Grayson : >> type1 *foo(const type1 *my_const_ptr) >> { >> union { >> type1 *t1; >> const type1 *ct1; >> } v; >> v.ct1 = my_const_ptr; >> return v.t1; >> } > > Yes, that is sad, and it seems like just a matter of time before a C++ >

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-07 Thread David Grayson
Oh, it would be a warning with -Wcast-qual, ok, got it. --David On Fri, Apr 7, 2017 at 8:21 AM, David Grayson wrote: > > type1 *foo(const type1 *my_const_ptr) > > { > > union { > > type1 *t1; > > const type1 *ct1; > > } v; > > v.ct1 = my_const_ptr; > > return v.t1;

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-07 Thread David Grayson
> type1 *foo(const type1 *my_const_ptr) > { > union { > type1 *t1; > const type1 *ct1; > } v; > v.ct1 = my_const_ptr; > return v.t1; > } Yes, that is sad, and it seems like just a matter of time before a C++ compiler looks at the code above and reasons that the write to ct1 can be optimized

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-07 Thread Norbert Pfeiler
That’s a kinda sad stance for a compiler support project, don’t you think? Best, Norbert. Liu Hao schrieb am Fr., 7. Apr. 2017 um 05:48 Uhr: > On 2017/4/7 8:11, Norbert Pfeiler wrote: > > Wasn’t LH_Mouse’s point that even if the warning is explicitly turned on > it > >

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Liu Hao
On 2017/4/7 8:11, Norbert Pfeiler wrote: > Wasn’t LH_Mouse’s point that even if the warning is explicitly turned on it > wouldn’t be shown to the user? > > The situation for unions is different in C and C++: (I don’t think that > it’s just about constness changes anything) >

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Norbert Pfeiler
Wasn’t LH_Mouse’s point that even if the warning is explicitly turned on it wouldn’t be shown to the user? The situation for unions is different in C and C++: (I don’t think that it’s just about constness changes anything) http://stackoverflow.com/questions/11373203 Best, Norbert. Kai Tietz

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Kai Tietz
2017-04-06 15:06 GMT+02:00 Liu Hao : > On 2017/4/6 20:47, Kai Tietz wrote: >> True. The reason why we prefer such patter is that it works in both >> languages as desired. Otherwise we would be in need to write >> different variants for the languages C/C++. This looks backward,

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Kai Tietz
2017-04-06 14:47 GMT+02:00 Kai Tietz : > 2017-04-06 13:38 GMT+02:00 Norbert Pfeiler > : >> I’m pretty sure that cast via union is UB in C++ whereas C-style casting >> away constness isn’t (only writing to the resulting object would be)

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Liu Hao
On 2017/4/6 20:47, Kai Tietz wrote: > True. The reason why we prefer such patter is that it works in both > languages as desired. Otherwise we would be in need to write > different variants for the languages C/C++. This looks backward, and > it still doesn't make sure that there might be

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Kai Tietz
2017-04-06 13:38 GMT+02:00 Norbert Pfeiler : > I’m pretty sure that cast via union is UB in C++ whereas C-style casting > away constness isn’t (only writing to the resulting object would be) but it > may result in compilers issuing warnings about style (because

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Norbert Pfeiler
I’m pretty sure that cast via union is UB in C++ whereas C-style casting away constness isn’t (only writing to the resulting object would be) but it may result in compilers issuing warnings about style (because C++ has const_cast). Best, Norbert. Kai Tietz schrieb am

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Kai Tietz
A cast via union looks like this: type1 *foo(const type1 *my_const_ptr) { union { type1 *t1; const type1 *ct1; } v; v.ct1 = my_const_ptr; return v.t1; } The advantage of such a pattern is that no type conversion errors/warnings are shown. So for casting from const to none-const, this variant

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-05 Thread Liu Hao
On 2017/4/5 21:51, Mateusz Mikuła wrote: > Conversion from const pointer to normal pointer is definitely unsafe but > that's probably what GCC just did. > I'm unsure what you mean by "union-cast" but you can commit your fix. Take a look at the prototype of the `strchr` function in the C standard

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-05 Thread Mateusz Mikuła
> Hmm, using here "wchar_t *" as cast looks wrong. Actually we should > use anyway PUWSTR_C instead. I noticed it a bit too late and sent another patch casting to PUWSTR_C. > Nevertheless we can have here a const/none-const conversion (means > const specifiers for C-runtime function isn't

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-05 Thread Kai Tietz
hr(PCUWSTR String,WCHAR Character) { > -if(WSTR_ALIGNED(String)) return wcsrchr((PCWSTR)String,Character); > +if(WSTR_ALIGNED(String)) return (wchar_t > *)wcsrchr((PCWSTR)String,Character); > return (PUWSTR_C)uaw_wcsrchr(String,Character); >} > #if defined

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-05 Thread Mateusz Mikuła
On second though casting to "PUWSTR_C" which is could be more appealing. Attaching improved patch. -- Original Message -- Subject: Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t * Date: Wed, 5 Apr 2017 15:06:41 +0200 To: Mingw-

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-05 Thread Mateusz Mikuła
p;& defined(_WConst_Return) -- 2.12.1 -- Original Message -- Subject: Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t * Date: Wed, 5 Apr 2017 14:26:50 +0200 To: Mingw-w64-public From: Kai Tietz > Hello Mateusz, > > could you p

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-05 Thread Kai Tietz
Hello Mateusz, could you please re-attach, or simply inline patch to this mail? Thanks in advance, Kai 2017-04-05 14:08 GMT+02:00 Mateusz Mikuła : > Ping, looks like it slipped unnoticed. > > > > > -- Original Message -- > Subject: [PATCH] stralign: cast ua_wcschr

Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-05 Thread Mateusz Mikuła
Ping, looks like it slipped unnoticed. -- Original Message -- Subject: [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t * Date: Mon, 3 Apr 2017 14:01:00 +0200 To: Mingw-w64-public From: Mateusz Mikuła > > I made another attempt to build libc++ with mingw-w64 and

[Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-03 Thread Mateusz Mikuła
I made another attempt to build libc++ with mingw-w64 and stumbled across Clang errors: |D:\msys64\mingw64\x86_64-w64-mingw32\include\windows.h:114: D:\msys64\mingw64\x86_64-w64-mingw32\include\stralign.h:121:37: error: cannot initialize return object of type 'PUWSTR_C' (aka 'wchar_t *') with an