Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with [expr.ass]p3 with initializer lists and ambiguity of term "expression" #1906

Closed
RealLitb opened this issue Jan 31, 2018 · 2 comments

Comments

@RealLitb
Copy link

This is really two issues. First,

p2 says "In simple assignment (=), the value of the expression replaces that of the object referred to by the left operand."
p3 says "If the left operand is not of class type, the expression is implicitly converted ([conv]) to the cv-unqualified type of the left operand.".

In especially p2, it's confusing that this says "expression", when both the left and right operands are expressions (in fact, the right operand is not always an expression, since it may be an initializer list!). I suggest

p2 says "In simple assignment (=), the value of the right operand replaces that of the object referred to by the left operand."
p3 says "If the left operand is not of class type, it is implicitly converted ([conv]) to the cv-unqualified type of the left operand.".

Secondly, for "scalar assignment-op { }" we are told "an assignment to a scalar, in which case the initializer list shall have at most a single element. The meaning of x = {v}, where T is the scalar type of the expression x, is that of x = T{v}. The meaning of x = {} is x = T{}". But what about compound assignment operator? Is it undefined behavior? The prior paragraph that supposedly defines compound assignment says "The behavior of an expression of the form E1 op= E2 is equivalent to E1 = E1 op E2 except that E1 is evaluated only once.". But "E1 + {}" is not valid. It is not clear what this means: A syntactic ill-formed construct shall be equivalent with a syntactic well-formed construct?

Compiler survey: Clang-3.8 accepts "int a = 0; a += { 2 }", GCC-7.2 rejects.

@cpplearner
Copy link
Contributor

For the first part, see #720 .

For the second part, CWG 1542 is probably relevant.

@RealLitb
Copy link
Author

Already covered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants