RFA: PATCH to initializer_constant_valid_p for c++/38880

H.J. Lu hjl.tools@gmail.com
Tue Feb 24 09:31:00 GMT 2009


On Mon, Feb 23, 2009 at 1:05 PM, Jason Merrill <jason@redhat.com> wrote:
> Ian Lance Taylor wrote:
>>
>> Use a cast.  The initializer_constant_valid_p code will look through
>> casts.
>
> Good point, with a cast I was able to make it do odd things.  Fixed thus,
> and regression tested x86_64-pc-linux-gnu.  OK for trunk?
>
>

bash-3.2$ cat g++.dg/init/static-init1.C
// Related to the patch for 38880.
// Make sure we don't think we can initialize a at compile time.

char c;
short a[] = { (short)((int)&c + (int)&c) };
bash-3.2$

Doesn't work on Linux/x86-64.  I think this patch:

Index: g++.dg/init/static-init1.C
===================================================================
--- g++.dg/init/static-init1.C	(revision 144401)
+++ g++.dg/init/static-init1.C	(working copy)
@@ -2,4 +2,4 @@
 // Make sure we don't think we can initialize a at compile time.

 char c;
-short a[] = { (short)((int)&c + (int)&c) };
+short a[] = { (short)((__PTRDIFF_TYPE__)&c + (__PTRDIFF_TYPE__)&c) };
bash-3.2$

may work.

-- 
H.J.



More information about the Gcc-patches mailing list