Title
Class/enumeration names vs conditions
Status
nad
Section
Clause [8] [stmt.stmt]
Submitter
Daveed Vandevoorde

Created on 2017-05-04.00:00:00 last changed 81 months ago

Messages

Date: 2018-04-15.00:00:00

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.

Date: 2022-11-20.07:54:16

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?

History
Date User Action Args
2018-04-11 00:00:00adminsetmessages: + msg6213
2018-04-11 00:00:00adminsetstatus: open -> nad
2017-05-04 00:00:00admincreate