-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
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 ifN != 0
, and accepts withN == 0
.- GCC says
arr+N
is always constant (even though it sometimes has UB), but rejects reading*p
ifarr+N
is out of bounds.- ICC says
arr+N
is always constant (even though it sometimes has UB), but always rejects reading*p
even ifarr+N
is in-bounds.- MSVC says you can’t declare
arr
as non-constexpr and define it constexpr, even though there is no such ruleThis, 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:
Metadata
Metadata
Assignees
Labels
No labels