Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is an id-expression?

I'm having a problem clearly understanding exactly what an id-expression is. I'll start off by following what I found in the most recent working draft of the C++ standard starting off with:

enter image description here

Venturing to the definition of an identifier:

An identifier is an arbitrarily long sequence of letters and digits.

So it seems like any arbitrary long sequence of letters and digits can be an id-expression, but wait:

enter image description here

So the identifier must be declared first in order for it to be an id-expression? Well lets head over to clause 7:

enter image description here

Continuing...

enter image description here

Continuing again...

enter image description here

We arrive here:

enter image description here

I interpret this to mean an id-expression requires an identifier to be declared which requires an id-expression. This seems like a circular definition. Can someone tell me where I went wrong?

Anyway, my interpretation is that the identifier must be declared first in order for it to be considered an id-expression, but isn't that really just a name? The standard states that:

Every name that denotes an entity is introduced by a declaration.

So why not just call it a name-expression instead?

like image 944
JustinBlaber Avatar asked Jul 15 '15 20:07

JustinBlaber


1 Answers

You're misinterpreting [expr.prim.general]/8:

An identifier is an id-expression provided it has been suitably declared (Clause 7).

The phrase's intention is to disallow the usage of undeclared identifiers in expressions. I.e. this paragraph talks about id-expressions occurring as primary-expressions, not id-expressions occurring in declarators. I agree that the phrase is misleading and should be fixed. I filed a core issue.

So why not just call it a name-expression instead?

Historical reasons; the subtle distinction between identifiers and names was made after the very fundamental grammatical constructs (id-expression, unqualified-id, etc.) were named, and from there onwards, renaming those wasn't an option.

like image 160
Columbo Avatar answered Nov 17 '22 02:11

Columbo