noreturn declarationsAuthors: Joseph Myers
Date: 2026-03-25
Submitted against: C23
Status: Open
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?