Issue 1068: Standard pragmas after labels

Authors: Jay Ghiron
Date: 2026-05-27
Submitted against: C23
Status: Open

All of the standard pragmas contain wording to require use in specific contexts:

The pragma can occur either outside external declarations or preceding all explicit declarations and statements inside a compound statement.

(C23 7.3.4 "The CX_LIMITED_RANGE pragma" paragraph 2.)

The pragma shall occur either outside external declarations or preceding all explicit declarations and statements inside a compound statement.

(C23 7.6.2 "The FENV_ACCESS pragma" paragraph 2.)

The pragma shall occur either outside external declarations or before all explicit declarations and statements inside a compound statement.

(C23 7.6.3 "The FENV_ROUND pragma" paragraph 2.)

Each pragma can occur either outside external declarations or preceding all explicit declarations and statements inside a compound statement.

(C23 7.12.3 "The FP_CONTRACT pragma" paragraph 2.)

Before C23, "all explicit declarations and statements" meant that nothing could be used before these pragmas in a compound statement. In C23 the definition of block items in a compound statement was changed so that labels can be used at the end of a block without any following statement, and can be used preceding a declaration (N2508). Consequently it appears the following is now valid:

int main(){
label:
#pragma STDC FENV_ACCESS OFF
}

While even using a null statement before is undefined. It seems unintended to allow labels to be used like this while placing restrictions on other block items.

Suggested correction

Modify C23 7.3.4 paragraph 2:

The pragma can occur either outside external declarations or preceding all explicit declarations and statementsblock items inside a compound statement.

Modify C23 7.6.2 paragraph 2:

The pragma shall occur either outside external declarations or preceding all explicit declarations and statementsblock items inside a compound statement.

Modify C23 7.6.3 paragraph 2:

The pragma shall occur either outside external declarations or before all explicit declarations and statementsblock items inside a compound statement.

Modify C23 7.12.3 paragraph 2:

Each pragma can occur either outside external declarations or preceding all explicit declarations and statementsblock items inside a compound statement.

Modify C23 J.2 paragraph 1:

The CX_LIMITED_RANGE, FENV_ACCESS, FENV_ROUND, FENV_DEC_ROUND, or FP_CONTRACT pragma is used in any context other than outside all external declarations or preceding all explicit declarations and statementsblock items inside a compound statement (7.3.4, 7.6.2, 7.6.3, 7.6.4, 7.12.3).

Note: Each of the standard pragmas express these requirements differently. Since the result is supposed to be undefined if the requirements are not met, they should probably all use the "shall" wording.