On 10/3/21 4:38 AM, Pádraig Brady wrote:
I'm confused as to why some functions need _Noreturn and some don't.

Yes, it's a bit of a pain. _Noreturn is useful on extern functions, since otherwise GCC typically won't know the function doesn't return. On static functions, though, _Noreturn generally isn't needed since GCC can figure it out.

Unfortunately, I needed to keep _Noreturn on three static functions in Coreutils to pacify GCC into not generating the following false alarms. Today I reported this issue as GCC bug 102578 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102578>.

  src/csplit.c: In function 'xalloc_die':
  src/csplit.c:235:1: error: 'noreturn' function does return [-Werror]
    235 | }
        | ^

  src/sort.c: In function 'open_temp':
src/sort.c:1206:7: error: this statement may fall through [-Werror=implicit-fallthrough=] 1206 | async_safe_die (errno, "couldn't execute compress program (with -d)"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  src/sort.c:1208:5: note: here
   1208 |     default:
        |     ^~~~~~~

  src/test.c: In function 'find_int':
src/test.c:161:1: error: control reaches end of non-void function [-Werror=return-type]
    161 | }
        | ^



Reply via email to