That non-normative note in the standard is intended to motivate the concept of an expression, but is not the actual definition. The definition of expression is given in the language grammar which is given in the remainder of clause 5. Expressions are built out of certain terminals such as literals, names of variables, and names of functions, which are combined using operators such as arithmetic and relational operators.
Declarations and expressions are distinct syntactic entities, so a declaration found inside a C++ program is never an expression, and vice versa. The difference is fairly easy to see at a glance: if it declares something, it's a declaration.
1; // expression statement
int i = 1; // declaration statement that declares `i`
A(i, 42); // expression statement that creates an A object
A a(i); // declaration statement that declares an A object (named a)
A declaration can evaluate expressions but a declaration is not an expression. You rightly point out that the declaration of an object of class type can cause a constructor call. Still it is syntactically a declaration and not an expression.
However, there is another sense in which a declaration is an expression. Namely, rules about the sequencing of evaluations within expressions also apply to declarations. For example, there is a rule that the side effect of a postfix increment on an int
takes place at some point before the end of the full-expression.
f(i++) + g(); // i may be incremented before or after g() is called...
h(); // but definitely before h() is called.
For the purposes of such rules, the declaration and initialization of a single variable is considered to also be a full-expression. In the case of a variable of class type, the constructor call is part of that expression.
int i = 1; // this declaration evaluates a full-expression
// whose effect is to initialize `i` to 1
int j = f(i++) + g(), k = h(); // two separate full-expressions;
// i is incremented before h() is called
When reading the standard, you need to consider the context in order to figure out what sense of "expression" is meant.
x = (int i=1;)
. – Capps42
is aliteral
, which is aprimary-expression
. I don't know why you think it isn't. The note is non-normative, and does not define expressions. – Like