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:
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:
So the identifier
must be declared first in order for it to be an id-expression
? Well lets head over to clause 7:
Continuing...
Continuing again...
We arrive 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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With