You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thanks for reporting this, quite interesting. I briefly looked into it and in the AST at this point there are no parentheses. I need to look deeper into it to figure out what I can do.
it looks like I finally understood it. I believe that this is a special case with fold expression. Their pattern is specified in the standard [temp.variadic] p10.1 - p10.2. Hence it does not require parentheses. A patch is on its way to add them in case of + or -.
When expanding folding expressions, the generated code doesn't have parenthesis even though they are needed for some (most?) operators.
In the example, the expression is interpreted as
(0 - (0 - 5))
which is5
, but written on the right as0 - 0 - 5
which is-5
.See https://cppinsights.io/lnk?code=dGVtcGxhdGU8aW50Li4uIEludHM+CmNvbnN0ZXhwciBpbnQgZm9sZF9taW51c19pbXBsKCkgewogICAgcmV0dXJuIChJbnRzIC0gLi4uIC0gNSk7Cn0KCnRlbXBsYXRlPGludC4uLiBJbnRzPgpjb25zdGV4cHIgaW50IGZvbGRfbWludXMoKSB7CiAgICByZXR1cm4gZm9sZF9taW51c19pbXBsPDAsIEludHMuLi4+KCk7Cn0KCnN0YXRpY19hc3NlcnQoZm9sZF9taW51cygpID09IC01KTsKCnRlbXBsYXRlIDxpbnQgYj4KY2xhc3MgcHJpbnRfaW50OwoKaW50IGkgPSBmb2xkX21pbnVzPDA+KCk7CnN0YXRpY19hc3NlcnQoZm9sZF9taW51czwwPigpID09IDUpOwpzdGF0aWNfYXNzZXJ0KDAgLSAwIC0gNSA9PSAtNSk7CgovL3ByaW50X2ludDxmb2xkX21pbnVzPDA+KCk+IHA7&rev=1.0
The text was updated successfully, but these errors were encountered: