On Wed, 2020-02-26 at 15:51 -0700, Martin Sebor wrote:
> GCC accepts attribute format even on functions without a prototype.
> However, when such a function is subsequently redeclared with
> a prototype the attribute validation runs into trouble.  To avoid
> the ICE I considered a) dropping the attribute on functions declared
> without a prototype (like Clang does) and b) dropping the attribute
> only when the function is subsequently redeclared with a prototype.
> Since (b) is slightly safer in terms of retaining potentially useful
> functionality the attached patch implements it and verifies that
> the attribute is still accepted on functions without a prototype
> and has the expected effect.
> 
> Tested on x86_64-linux.  I propose this for both GCC 10 and 9.
> 
> Martin
> 
> PS The solution causes a redunant warning for each instance of
> a redeclaration with a prototype of a function without a prototype
> but with attribute format.  Since this seems like a rare problem
> I don't think it's worth going to the trouble of making sure only
> one warning.
> 
> PPS I don't think it's intentional that GCC accepts attribute format
> on functions without a prototype, first because it normally requires
> that the format argument be a char*, and second because I could find
> no tests for the "feature" in the test suite.  It would make sense
> to me reject such declarations but I don't think now is a good time
> for such a change.

> PR c/93812 - ICE on redeclaration of an attribute format function without
> protoype
> 
> gcc/c/ChangeLog:
> 
>       PR c/93812
>       * c-typeck.c (build_functype_attribute_variant): New function.
>       (composite_type): Call it.
> 
> gcc/testsuite/ChangeLog:
> 
>       PR c/93812
>       * gcc.dg/format/proto.c: New test.
OK.  

If you want to drop like Clang for gcc-11, that's fine with me, but we'll
definitely want to warn when we drop and document the behavior change.

Thanks,
Jeff

Reply via email to