1
0
mirror of https://github.com/golang/go synced 2024-09-29 02:14:29 -06:00
go/doc
Matthew Dempsky 856cf23a8a spec: specify evaluation order for binary logical operations
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>
2023-09-14 05:14:44 +00:00
..
asm.html doc/asm: fix HTML markup 2021-09-10 17:15:37 +00:00
go1.17_spec.html doc: fix html tags 2023-08-03 14:43:29 +00:00
go1.22.html reflect: make Value.IsZero identical to v == zero 2023-09-01 23:20:30 +00:00
go_mem.html doc: fix html tags 2023-08-03 14:43:29 +00:00
go_spec.html spec: specify evaluation order for binary logical operations 2023-09-14 05:14:44 +00:00
godebug.md doc: fix broken x509sha1 setting link 2023-08-15 19:38:07 +00:00