Issue 1102: Conditions for when types are inferred

Authors: Jay Ghiron
Date: 2026-09-01
Submitted against: C23
Status: Open

If auto appears with another storage-class specifier, or if it appears in a declaration at file scope, it is ignored for the purposes of determining a storage duration or linkage. In this case, it indicates only that the declared type can be inferred.

(C23 6.7.2 "Storage-class specifiers" paragraph 15.)

Consider the following:

int main(){
constexpr auto int x=0;
}

This should probably be invalid, but there does not appear to be any wording that actually prohibits this. Specifically, the type is inferred because another storage-class specifier appears with auto but there does not appear to be any prohibition on type inference with a type specifier. Additionally, consider the following:

int main(){
auto y=0;
}

This declaration does not have another storage-class specifier and does not appear at file scope, so it appears that the type is not inferred and therefore violates a constraint for not having a type specifier. I assume that it was not intended for this to be invalid.

There is a proposal N3579 currently that should fix these issues. The current text avoids actually defining when type inference happens, just defining when type inference can happen and applying constraints based off of if type inference happens. The following is a minimal correction that I believe will fix these issues.

Suggested correction

Modify C23 6.7.2 paragraph 15:

If auto appears with another storage-class specifier, or if it appears in a declaration at file scopeno type specifier, it is ignored for the purposes of determining a storage duration or linkage. In this case, it indicates only that the declared type can be inferred.


Comment from Issues list maintainer on 2026-09-09:

In reflector message 37789, Jens Gustedt suggested alternative wording in 6.7.2 paragraph 15:

If auto appears with another storage-class specifier, or if it appears in a declaration at file scope, it is ignored for the purposes of determining a storage duration or linkage. In this case, it indicates only that the declared type can is to be inferred.

This would be taken together with a change to Constraints in 6.7.10 paragraph 1:

A declaration for which the type is inferred shall contain the storage-class specifier auto and shall not contain any type specifiers`.

In reflector message 37793, Joseph Myers suggested there should be an actual definition in italics of inferred or inferred type.


Comment from Jay Ghiron on 2026-09-14:

Paragraph fifteen is the only place that defines when type inference can happen, so presumably everything else will never have the type inferred. I am not sure how the current text can be interpreted as allowing auto y=0; at block scope. The wording being different from paragraph four makes more sense, auto with a type specifier does not mean to infer the type and auto without a type specifier does mean to infer the type. In paragraph four the wording there forbids the combination of a type specifier (or multiple type specifiers), auto, and either file scope or another storage-class specifier. Uses of auto other than to infer the type have no effect so there is no wording to describe any behavior. The correction I have proposed should make it state exactly this.