public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/94171] New: attribute silently ignored on redeclarations of a typedef
@ 2020-03-13 21:09 msebor at gcc dot gnu.org
  0 siblings, 0 replies; only message in thread
From: msebor at gcc dot gnu.org @ 2020-03-13 21:09 UTC (permalink / raw)
  To: gcc-bugs

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)
      |   ^

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-03-13 21:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13 21:09 [Bug c/94171] New: attribute silently ignored on redeclarations of a typedef msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).