Issue 1037: Scopes and noreturn declarations

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


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.

Suggested correction

Modify C23 6.7.13.7 (The noreturn and _Noreturn attributes):

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.

If a function is declared with the noreturn attribute, then any other declaration of that function, in any translation unit, shall either specify the noreturn attribute, or be in a scope where a prior declaration of that function with the noreturn attribute is visible.

This change also addresses the first question in issue 1065.