Open
Description
Full name of submitter (unless configured in github; will be published with the issue): Jiang An
Reference (section label): [expr.add], [expr.const]
Link to reflector thread (if any):
Issue description:
In some circumstances, it is impossible to know whether a pointer arithmetic operation is well-defined if an unknown reference is involved during constant evaluation.
E.g. in the following example:
extern int& r; // defined in another TU
constexpr auto diff = &r + 42 - &r;
The reference r
might bind to a non-array-element object, or the first element to an int[1]
or int[42]
array, which affects the well-definedness of &r + 42 - &r
, but we can't know this during constant-initializing diff
.
Perhaps we want some conservative rule for such cases.
Suggested resolution:
Modify [expr.const] as indicated:
- [...] 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 whose lifetime and that of all subobjects includes the entire constant evaluation and whose dynamic type is constexpr-unknown. For the purpose of constant evaluation, the unspecified object is considered not to be an array element.
Metadata
Metadata
Assignees
Labels
No labels