noreturn declarationsAuthors: Joseph Myers
Date: 2026-03-25
Submitted against: C23
Status: Open
Cross-references: 1065
The specification for the [[noreturn]] attribute (C23 6.7.13.7)
says:
The first declaration of a function shall specify the
noreturnattribute if any declaration of that function specifies thenoreturnattribute. If a function is declared with thenoreturnattribute in one translation unit and the same function is declared without thenoreturnattribute in another translation unit, the behavior is undefined.
As noted in reflector message 35399 (16 Feb 2026), this is unclear about the meaning of the "first" declaration if there is a prior declaration that is not in scope:
void t()
{
[[noreturn]] void f();
}
void f();
[[noreturn]] void g();
void u()
{
int g;
{
void g();
}
}
Is the second declaration of f above valid, or invalid because the
noreturn declaration is not visible (being in a scope that has
ended) at the point of the second declaration?
Is the second declaration of g as a function above valid, or invalid
because g is shadowed in an inner scope by the block-scope
declaration of g as an object?
Comment from Issues list maintainer on 2026-11-26:
This issue was discussed at the November 2026 (Búzios) meeting of WG14. Joseph Myers took an action item to write wording to make both examples undefined behavior.
Comment from Issues list maintainer on 2026-12-01:
In reflector message 38700, Joseph Myers proposed the following wording.
Modify C23 6.7.13.7 (The noreturn and _Noreturn attributes):
The first declaration of a function shall specify thenoreturnattribute if any declaration of that function specifies thenoreturnattribute. If a function is declared with thenoreturnattribute in one translation unit and the same function is declared without thenoreturnattribute in another translation unit, the behavior is undefined.If a function is declared with the
noreturnattribute, then any other declaration of that function, in any translation unit, shall either specify thenoreturnattribute, or be in a scope where a prior declaration of that function with thenoreturnattribute is visible.
This change also addresses the first question in issue 1065.