I have this sample of code:
struct S {};
S s = S();
Per my understanding, I see that s = S() in the declaration S s = S() is an init-declarator where s is a declarator and = S() is an initializer.
Also, I see that the initializer (= S()) is a brace-or-equal-initializer which is "= initializer-clause". This means finally that S() is an initializer-clause.
By the grammar, an initializer-clause is either an assignment-expression or a braced-init-list. Indeed, S() might not be a braced-init-list, but it may be an assignment-expression.
If my analysis is correct so far, I have a question here:
How S() is an assignment-expression? Where is the assignment-operator in expression S()?
In other words, the grammar of assignment-expression is:
assignment-expression:
conditional-expression
yield-expression
throw-expression
logical-or-expression assignment-operator initializer-clause
how S() could be one of the above?
Similarly, the grammar of a throw-expression is
throw-expression:
throw assignment-expression
how S() in statement throw S(); is an assignment-expression?
Because it matches the first option conditional-expression as shown below. Note the emphasized part in each section/part and that at the end we reach to
simple-type-specifier ( expression-listopt )which isS().Next, we go to conditional expression:
Next, to logical-or-expression:
Next, to logical-and-expression:
From inclusive-or-expression:
Next, exclusive-or-expression
Now to and-expression
From relational-operator
Next from relational-expression
Next to compare-expression
Next to shift-expression
Next additive-expression
Next to multiplicative-expression
Next to pm-expression
Next to cast-expression
Next to unary-expression
Finally we reach postfix-expression