This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 112e. See for the official list.


2349. Class/enumeration names vs conditions

Section: Clause 8  [stmt.stmt]     Status: NAD     Submitter: Daveed Vandevoorde     Date: 2017-05-04

According to Clause 8 [stmt.stmt] paragraph 3,

A name introduced by a declaration in a condition (either introduced by the decl-specifier-seq or the declarator of the condition) is in scope from its point of declaration until the end of the substatements controlled by the condition. If the name is redeclared in the outermost block of a substatement controlled by the condition, the declaration that redeclares the name is ill-formed.

This does not exempt class and enumeration names, which can ordinarily coexist with non-type names in the same scope (_N4868_.6.4.10 [basic.scope.hiding] paragraph 2) . However, there is implementation variance in the handling of examples like:

   void g() {
     if (int N = 3) {
       struct N { } n; // ill-formed but not diagnosed by some implementations

Should the rule for conditions be updated to allow for this case?

Rationale (April, 2018):

Hiding of tag names by non-type names was added for C compatibility. C does not support conditions, and there was no consensus to extend the tag/non-type hiding rules into contexts where C compatibility is not required.