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

            Bug ID: 114833
           Summary: --suggest-attribute=returns_nonnull misdiagnoses
                    functions with __attribute__((nonnull))
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

This is gcc (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0) on Fedora 40 x86-64. Put
this code into the file t.i:

  extern char const *foo () __attribute__ ((returns_nonnull));
  char const *
  foo ()
  {
    return "abc";
  }

and compile it with:

  gcc -S -O2 -Wsuggest-attribute=returns_nonnull t.i

The output is:

  t.i: In function ‘foo’:
  t.i:3:3: warning: function might be candidate for attribute ‘returns_nonnull’
[-Wsuggest-attribute=returns_nonnull]
      3 |   foo ()
        |   ^~~

This diagnostic is obviously wrong, as foo is already declared with the
suggested attribute.

Reply via email to