mirror of
https://github.com/golang/go
synced 2024-11-23 20:40:07 -07:00
856cf23a8a
This CL clarifies the order of evaluation of the binary logical operators, && and ||. The clarified semantics matches what cmd/compile and x/tools/go/ssa already implement, and prohibit some optimizations that are arguably allowed today but risk surprising users. First, it specifies that the left operand is evaluated before the right operand. This prohibits "(f() || true) && *p" from evaluating "*p" before "f()". Second, it specifies that binary logical operations are also ordered lexically left-to-right with regard to function calls and receive operations. This prohibits "h(*p || true || f(), g())" from evaluating "*p" after "g()". Finally, the "order of evaluation of [...] is not specified" wording in the example is clarified to acknowledge that there are still some other orderings that are implied lexically; e.g., x must be evaluated and indexed before g(), and z now must be evaluated before h(). (Note: Whether z is evaluated before or after f() remains unspecified, as there's no lexical dependency.) Change-Id: I9d316a7f1fbc83be663e116380a2cc7a4ace623d Reviewed-on: https://go-review.googlesource.com/c/go/+/522938 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> |
||
---|---|---|
.. | ||
asm.html | ||
go1.17_spec.html | ||
go1.22.html | ||
go_mem.html | ||
go_spec.html | ||
godebug.md |