Full name of submitter (unless configured in github; will be published with the issue): Barry Revzin
Reference (section label): [expr.const]
Link to reflector thread (if any):
Issue description:
From P2280R4:
Perhaps the most fun example is this one:
extern const int arr[];
constexpr const int *p = arr + N;
constexpr int arr[2] = {0, 1};
constexpr int k = *p;
Which every compiler currently provides different results (in order of most reasonable to least reasonable):
- Clang says
arr+N is non-constant if N != 0, and accepts with N == 0.
- GCC says
arr+N is always constant (even though it sometimes has UB), but rejects reading *p if arr+N is out of bounds.
- ICC says
arr+N is always constant (even though it sometimes has UB), but always rejects reading *p even if arr+N is in-bounds.
- MSVC says you can’t declare
arr as non-constexpr and define it constexpr, even though there is no such rule
This, to me, seems like there should be an added rule in [expr.const] that rejects addition and subtraction to an array of unknown bound unless that value is 0. This case seems unrelated enough to the rest of the paper that I think it should just be a Core issue.
It seems that no CWG issue is created for this yet.
Suggested resolution:
Full name of submitter (unless configured in github; will be published with the issue): Barry Revzin
Reference (section label): [expr.const]
Link to reflector thread (if any):
Issue description:
From P2280R4:
It seems that no CWG issue is created for this yet.
Suggested resolution: