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

            Bug ID: 81544
           Summary: attribute noreturn and warn_unused_result on the same
                    function accepted
           Product: gcc
           Version: 8.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: ---

GCC silently accepts a function declaration that makes use of both attribute
noreturn and warn_unused_result.  The combination is meaningless as is evident
from the warnings issued for calls to such a function: regardless of whether
the function's return value is or isn't used GCC issues a warning.

Rather than accepting such meaningless combinations of attributes GCC should
validate them as they are accumulated from declarations and diagnose the
meaningless or invalid combinations early, before they are used.

$ cat b.c && gcc -O2 -S -Wall -Wextra -Wpedantic b.c
int __attribute__ ((noreturn)) foo (void);
int __attribute__ ((warn_unused_result)) foo (void);

int bar (void)
{
  int n = foo ();
  return n;
}

void baz (void)
{
  foo ();
}


b.c: In function ‘bar’:
b.c:6:7: warning: ignoring return value of ‘foo’, declared with attribute
warn_unused_result [-Wunused-result]
   int n = foo ();
       ^
b.c: In function ‘baz’:
b.c:12:3: warning: ignoring return value of ‘foo’, declared with attribute
warn_unused_result [-Wunused-result]
   foo ();
   ^~~~~~

Reply via email to