llvm / llvm/llvm-project

Redeclarations of functions that add noreturn should be diagnosed in C

Open
#167,630 6 comments 0 reactions 0 assignees View on GitHub
c23 clang:diagnostics
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following program demonstrates the issue:
```c
int x(),x[[noreturn]]();
int main(){}
```
> The first declaration of a function shall specify the noreturn attribute if any declaration of that function specifies the noreturn attribute. If a function is declared with the noreturn attribute in one translation unit and the same function is declared without the noreturn attribute in another translation unit, the behavior is undefined.

Section 6.7.13.7 "The noreturn and _Noreturn attributes" Paragraph 3 ISO/IEC 9899:2024

The first declaration of x doesn't specify noreturn while the redeclaration of x does specify noreturn, so this program is invalid. Clang correctly diagnoses this program in C++ mode. No wording exists to make these types of redeclarations invalid when using _Noreturn, so those shouldn't be rejected.

GCC also has the same issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122650

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.