This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-12-20
[Voted into the WP at the February, 2008 meeting as paperJ16/08-0056 = WG21 N2546.]
We've found an interesting parsing ambiguity with the new meaning ofauto. Consider:
typedef int T; void f() { auto T = 42; // Valid or not? }The question here is whether T should be a type specifier or astorage class? 9.2.9.7 [dcl.spec.auto] paragraph 1 says,
Theautotype-specifier has two meanings depending onthe context of its use. In adecl-specifier-seq that containsat least onetype-specifier (in addition toauto) thatis not acv-qualifier, theautotype-specifierspecifies that the object named in the declaration has automaticstorage duration.
In this case,T is atype-specifier, so thedeclaration is ill-formed: there is nodeclarator-id. Many,however, would like to seeauto work “just likeint,” i.e., forcingT to be redeclared inthe inner scope. Concerns cited included hijacking of the name intemplates and inline function bodies over the course of time if aprogram revision introduces a type with that name in the surroundingcontext. Although it was pointed out that enclosing the name inparentheses in the inner declaration would prevent any suchproblems, this was viewed as unacceptably ugly.
Notes from the April, 2007 meeting:
The CWG wanted to avoid a rule like, “ifauto canbe atype-specifier, it is” (similar to the existing“if it can be a declaration, it is” rule) because of thelookahead and backtracking difficulties such an approach would posefor certain kinds of parsing techniques. It was noted that thedifficult lookahead cases all involve parentheses, which would notbe a problem if only the “=” form of initializer werepermitted inauto declarations; only very limited lookaheadis required in that case. It was also pointed out that the “ifit can be atype-specifier, it is” approach results in aquiet change of meaning for cases like
typedef int T; int n = 3; void f() { auto T(n); }This currently declaresn to be anint variablein the inner scope but would, under the full lookahead approach,declareT to be a variable, quitely changing usesofn insidef() to refer to the outer variable.
The consensus of the CWG was to pursue the change to require the“=” form of initializer forauto.
Notes from the July, 2007 meeting:
See paper J16/07-0197 = WG21 N2337. There was no consensusamong the CWG for either of the approaches recommended in thepaper; additional input and direction is required.