cplusplus / CWG

Core Working Group
23 stars 7 forks source link

[expr.const] Clarify wording of "usable in constant expressions" #421

Closed mpolacek closed 10 months ago

mpolacek commented 10 months ago

Full name of submitter: Marek Polacek

Reference (section label): [expr.const]/4

Link to reflector thread (if any): N/A

Issue description: We say that V is usable in constant expressions if:

V is constexpr,
V is not initialized to a TU-local value, or
P is in the same translation unit as D.

but this is ambiguous; it could be read as either a || b || c or a && (b || c). The former is likely the intended reading.

Suggested resolution:

V is constexpr,<ins> or</ins>
V is not initialized to a TU-local value, or
P is in the same translation unit as D.
t3nsor commented 10 months ago

Why do you think that this grammatical structure can potentially be interpreted as "a && (b || c)"?

mpolacek commented 10 months ago

Why do you think that this grammatical structure can potentially be interpreted as "a && (b || c)"?

Because without the "or" or "and" it is not clear whether "V is constexpr" is a sufficient or necessary condition.

t3nsor commented 10 months ago

But we say things like "X, Y, and Z" and "X, Y, or Z" all the time. All native speakers understand these constructs to mean "X and Y and Z" and "X or Y or Z". So why is this part of the standard ambiguous?

mpolacek commented 10 months ago

But we say things like "X, Y, and Z" and "X, Y, or Z" all the time. All native speakers understand these constructs to mean "X and Y and Z" and "X or Y or Z". So why is this part of the standard ambiguous?

I guess I was confused because here it is immediately followed by "An object or reference is usable in constant expressions if it is" followed by a list where every bullet ends with "or". But, https://github.com/cplusplus/draft/wiki/Specification-Style-Guidelines#lists deems both styles OK so I suppose we can close this issue.