Skip to content

[basic.scope.block] p1 When a component matches multiple items #207

Open
@xmh0511

Description

@xmh0511

Full name of submitter (unless configured in github; will be published with the issue): Jim X

Each

  • selection or iteration statement ([stmt.select], [stmt.iter]),
  • substatement of such a statement,
  • handler ([except.pre]), or
  • compound statement ([stmt.block]) that is not the compound-statement of a handler

introduces a block scope that includes that statement or handler.

[Note 1: A substatement that is also a block has only one scope. — end note]

The note only implies that, when a compound statement is a substatement of a selection or iteration statement, even though it will match the second and the last item, it only be considered as introducing one block scope.

How about a selection or iteration statement A itself is a substatement of another selection or iteration statement? How many block scopes does the statement A introduce? We do not have a note to direct the reading for the case. It is the issue cplusplus/draft#4841

For example, saying

Each

  • number that is greater than 5, or
  • number that is greater than 10

will give you one score.

If you have a number 20, how many scores will you get? At least, this is ambiguous if we meet the case that matches more than one item.

Moreover, given a more natural example:

There are A, B, and C three students in the classroom, where A's age is 20, B's age is 21, C's age is 19, the teacher wants to do a survey about students' age, the teacher asks each person in the classroom whose age is greater than 10 puts your hands up, then A, B, C all put their hands up. Then, in the second round, the teacher says each person in the classroom whose age is greater than 18 puts her hands up. Only A and B put their hands up. The teacher ask C, what's your age, C says 19, the teacher asks why you didn't put your hands up in the second round??? C says: because I just have put my hands up in the first round. The reason sounds a bit strange.

Back to the issue, the note regarding block itself implies that we could consider a component can introduce more than one block scope if the component matches multiple items.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions