-
Notifications
You must be signed in to change notification settings - Fork 7
Closed
Description
P2741R3 user-generated static_assert messages specifies that
if the static_assert-message is a conditional-expression M,
–M.size()
shall be a converted constant expression of type std::size_t and let N
denote the value of that expression,
–M.data()
, implicitly converted to the type ”pointer to const char”, shall be a core
constant expression and let D denote the converted expression
However, consider
struct array {
constexpr unsigned long size() const {
return 2;
}
constexpr const char* data() const {
return d_;
}
const char d_[2];
};
static_assert(false, array{'a', 'b'});
This static_assert
message does not (but should) satisfy the requirements.
The issue here is that std::array<char, 2>{'a', 'b'}.data()
produces a pointer that contains the address of an object that does not have static storage duration. In fact it returns a pointer to a subobject of a...temporary?
[dcl.pre] Should establish that
- the expression
M
produces a temporary object that is usable in constant expression (and whose lifetime ends when the message is produced?) - Maybe not say anything about
M.data()
being a constant expression - onlyM.data()[N]
which definitely needs to be a constant expression. - Alternatively, establish that all of these evaluations happen in the same context, although this seems more complicated.
Metadata
Metadata
Assignees
Labels
No labels