This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] fix PR39701 testsuite failures


On Fri, 10 Apr 2009, Paolo Bonzini wrote:

> The third kind of failure is in the PR36901 testcases, which do
> 
>   int sc = (&sc > 0);
> 
> to emit a pedwarn, and this now triggers an "initializer is not
> constant" error when -fno-delete-null-pointer-checks.  Previously, the
> comparison was folded to true.  My first impression is that the warning
> *is* correct (you need to wait until linking to know the address of &sc
> with -fno-delete-null-pointer-checks).  So I'm changing it to
> 
>   int sc = (&sc > 0) ? 1 : 1;
> 
> This abuses the COND ? A : A folding to make sure that the initializer
> is considered constant.
> 
>   Observation: I'm CCing Joseph to understand how and if this is correct
>   from a C standard point of view, since this seems to me like a case
>   of extra folding performed by GCC on initializers.

This is one of the areas where an expression is not one of the types of 
constant expressions listed in the C standard, but does not violate any of 
the constraints on constant expressions, so implementations are permitted 
to accept such expressions in initializers.  It does fall outside my 
formal models of constant expressions, but if those are implemented in 
future for initializers a pedwarn (or warning) rather than an error would 
suffice.

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]