[RFC] warning: initialization discards qualifiers from pointer target type

James E Wilson wilson@specifixinc.com
Tue Apr 19 19:04:00 GMT 2005


Devang Patel wrote:
> On Apr 18, 2005, at 6:29 PM, James E Wilson wrote:
>> I notice that these are pedwarns,
> In that case, we can enable it only when -pedantic is used (like many  
> pedwarns) ?

Consider this small modification to your testcase.

const char *a( void )
{
   return "abc";
}

int main( void )
{
   char *s = a();
   s[0] = 'c';
   return 0;
}

This will core dump when run on any system that write-protects read-only 
data.  The only warning that you will get from gcc is the one that you 
are asking us to disable.  This is the reason for the warning, as it is 
necessary to detect unsafe code like this.

I don't believe this warning should depend on -pedantic, as it is doing 
something useful.  I think a special -Wno- option makes more sense.

I was going to ask why you need this change, but you already answered 
that question.  If I had a customer getting 55k+ warnings, I'd want to 
add an option for them also.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com



More information about the Gcc mailing list