[Bug c/94171] New: attribute silently ignored on redeclarations of a typedef

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Mar 13 21:09:50 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94171

            Bug ID: 94171
           Summary: attribute silently ignored on redeclarations of a
                    typedef
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The attribute machinery silently drops attributes from subsequent type
definitions.  The test case below shows this with attribute nonnull but other
attributes that apply to types are affected as well.

Intel ICC behaves correctly and diagnoses all seven instances of passing a null
to a nonnull argument.

$ cat x.c && gcc -S -Wall -Wextra x.c
extern int a[];

typedef __attribute__ ((nonnull (1))) void F1 (void*, void*);

void f1 (F1 *p)
{
  p (a, 0);
  p (0, a);    // -Wnonnull (good)
}

typedef __attribute__ ((nonnull (1))) void F1_2 (void*, void*);
typedef __attribute__ ((nonnull (2))) void F1_2 (void*, void*);

void f12 (F1_2 *p)
{
  p (a, 0);    // missing -Wnonnull
  p (0, a);    // -Wnonnull (good)
}

typedef __attribute__ ((nonnull (2))) void F2_1 (void*, void*);
typedef __attribute__ ((nonnull (1))) void F2_1 (void*, void*);

void f21 (F2_1 *p)
{
  p (a, 0);    // -Wnonnull (good)
  p (0, a);    // missing -Wnonnull
}

typedef                               void Fx_1_2 (void*, void*);
typedef __attribute__ ((nonnull (1))) void Fx_1_2 (void*, void*);
typedef __attribute__ ((nonnull (2))) void Fx_1_2 (void*, void*);

void fx12 (Fx_1_2 *p)
{
  p (a, 0);    // missing -Wnonnull
  p (0, a);    // missing -Wnonnull
}
x.c: In function ‘f1’:
x.c:8:3: warning: null argument where non-null required (argument 1)
[-Wnonnull]
    8 |   p (0, a);    // -Wnonnull (good)
      |   ^
x.c: In function ‘f12’:
x.c:17:3: warning: null argument where non-null required (argument 1)
[-Wnonnull]
   17 |   p (0, a);    // -Wnonnull (good)
      |   ^
x.c: In function ‘f21’:
x.c:25:3: warning: null argument where non-null required (argument 2)
[-Wnonnull]
   25 |   p (a, 0);    // -Wnonnull (good)
      |   ^


More information about the Gcc-bugs mailing list