[cfe-dev] Clang ignores nonnull attributes on declarations following definitions when compiling as C++

Tom Honermann thonermann at coverity.com
Thu Jul 16 08:44:36 PDT 2015


On 07/15/2015 02:29 PM, Richard Smith wrote:
> On Mon, Jul 13, 2015 at 8:15 AM, Tom Honermann <thonermann at coverity.com
> <mailto:thonermann at coverity.com>> wrote:
>
>     Clang (3.4-trunk) ignores nonnull attributes on declarations
>     following definitions when compiling as C++, but not as C.  I
>     presume the difference has to do with tentative definitions in C.
>
>     A test case is below.  Recent versions of gcc and EDG both allow
>     nonnull attributes on declarations following a definition, at least
>     for this test case.  Is it desirable for Clang to act differently in
>     this respect?
>
>
> We don't support adding attributes after a definition. (In the case
> where the attributes affect the generated code for the definition, that
> way lies madness, and we don't distinguish between those attributes and
> others for consistency -- note that nonnull *does* affect code
> generation in some cases.) The difference between C and C++ here is most
> likely exactly what you suspect (the first declaration is only a
> tentative definition in C).

Ok, I can't disagree with your reasoning.  I had opened PR24134 
(https://llvm.org/bugs/show_bug.cgi?id=24134) for this.  Feel free to 
close it as WONTFIX.

I would be surprised if such usage is a common case, but perhaps the 
difference in behavior with respect to gcc should be noted somewhere?  I 
discovered the difference while testing merging of nonnull attributes 
across multiple declarations, not in real code.

Tom.



More information about the cfe-dev mailing list