cplusplus / CWG

Core Working Group
23 stars 7 forks source link

[expr.const] Unknown references to functions in constant evaluation #504

Open frederick-vs-ja opened 7 months ago

frederick-vs-ja commented 7 months ago

Full name of submitter (unless configured in github; will be published with the issue): Jiang An

Reference (section label): [expr.const]

Link to reflector thread (if any):

Issue description: [expr.const] p9 (added by P2280R4) only specifies the rules for references to objects and seemingly ignores references to functions.

Perhaps we should specify that a reference to function that is not usable in constant expressions would be treated as binding to an unspecified non-constexpr function.

Suggested resolution:

jensmaurer commented 7 months ago

This feels like a feature request, not a core issue. Yes, references to functions are not covered, which means their treatment is not extended.

It seems the standard is clear as written in this regard:

During the evaluation of an expression E as a core constant expression, all id-expressions and uses of *this that refer to an object or reference whose lifetime did not begin with the evaluation of E are treated as ...

t3nsor commented 7 months ago

This feels like a feature request, not a core issue. Yes, references to functions are not covered, which means their treatment is not extended.

It seems the standard is clear as written in this regard:

During the evaluation of an expression E as a core constant expression, all id-expressions and uses of *this that refer to an object or reference whose lifetime did not begin with the evaluation of E are treated as ...

If we think the intent of P2280 was to exclude references to functions, then we need to restore the old [expr.const]/5.12 in the case of references to functions, i.e., it must be always illegal to evaluate an id-expression denoting a reference to function unless that reference either is usable in constant expressions or began its lifetime within the constant evaluation.

And [expr.const]/9 also needs to be adjusted. The text "all id-expressions ... that refer to an object or reference whose lifetime did not begin within the evaluation of E" includes references that refer to functions. Then we say "For such a reference that is not usable in constant expressions, the reference is treated as binding to an unspecified object of the referenced type..." which can't be right.