Issue 1037: Scopes and noreturn declarations

Authors: 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 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.

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();
  }
}

Question 1

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?

Question 2

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?