n4527 5.20 [expr.const]p3
an integral constant expression expression of integral or unscoped enumeration type, implicitly converted prvalue, converted expression core constant expression.
5.20 [expr.const]p5
a constant expression either glvalue core constant expression value refers entity permitted result of constant expression (as defined below), or prvalue core constant expression value object where, object , subobjects:
(5.1) — each non-static data member of reference type refers entity permitted result of constant expression, and
(5.2) — if object or subobject of pointer type, contains address of object static storage duration, address past end of such object (5.7), address of function, or null pointer value.
an entity permitted result of constant expression if object static storage duration either not temporary object or temporary object value satisfies above constraints, or function.
void foo(){ const int = 1;//a has automatic storage duration // ok in gcc 5.1.0 , clang 3.8.0 int b[a]{}; static_assert(a,""); switch(1){ case a: ; } } question1: a integral constant expression?
question2: a constant expression?
question3: glvalue integral constant expression constant expression?
question4:
if answer of question 3 yes, conflict 5.20 p3 if object has automatic storage duration?
is
aintegral constant expression?
in following contexts:
int b[a]{}; static_assert(a,""); switch(1){ case a: ; } yes, a integral constant expression. starting first quote:
an integral constant expression expression of integral or unscoped enumeration type, implicitly converted prvalue, converted expression core constant expression.
'a' integral type, in cases implicitly converted prvalue, a core constant expression? yes, if go paragraph 2 defines not core constant expression:
a conditional-expression e core constant expression unless evaluation of e, following rules of abstract machine (1.9), evaluate 1 of following expressions
it has following clause:
an lvalue-to-rvalue conversion (4.1) unless applied to
with following exception:
a non-volatile glvalue of integral or enumeration type refers complete non-volatile const object preceding initialization, initialized constant expression, or
which applies a since non-volatile, const , initialized constant expression.
is
aconstant expression?
in same contexts above, yes, since can see quote above core constant expression.
is glvalue integral constant expression constant expression?
no, in order integral constant expression must converted prvalue , threfore can not glvalue.
Comments
Post a Comment