当规则说初始化的完整表达式时,这是完整表达式
which is the full-expression when the rule says the full-expression of initialization
struct S {
constexpr S(int i): I(i),D(i) { } // full-expressions are initialization of I and initialization of D
private:
int I;
int D;
};
int main(){
constexpr S s1 = 1; //full-expression comprises call of S::S(int)
}
根据full-expression的定义:
A full-expression is
- an unevaluated operand,
- a constant-expression,
- an init-declarator or a mem-initializer, including the constituent expressions of the initializer,
- an invocation of a destructor generated at the end of the lifetime of an object other than a temporary object, or
- an expression that is not a subexpression of another expression and that is not otherwise part of a full-expression.
For an initializer, performing the initialization of the entity (including evaluating default member initializers of an aggregate) is also considered part of the full-expression.
项目符号 3 说 s1 = 1
是一个完整表达式,因为它是一个初始化声明符,而 I(i)
是一个完整表达式,因为它是一个 mem-initializer
并且对于 D(i)
。这意味着初始化实体 s1
可以包含多个完整表达式?在这种情况下,这组全表达式中初始化的全表达式是哪个?
当然,完整表达式可以动态嵌套:考虑
void f(int i) {
++i; // (useless) full-expression
}
void g() {
f(1); // full-expression
}
因此,初始化 s1
是 init-declarator 完整表达式的一部分,同时还包含其 [=16= 的完整表达式之间没有冲突]内存初始化器s.
struct S {
constexpr S(int i): I(i),D(i) { } // full-expressions are initialization of I and initialization of D
private:
int I;
int D;
};
int main(){
constexpr S s1 = 1; //full-expression comprises call of S::S(int)
}
根据full-expression的定义:
A full-expression is
- an unevaluated operand,
- a constant-expression,
- an init-declarator or a mem-initializer, including the constituent expressions of the initializer,
- an invocation of a destructor generated at the end of the lifetime of an object other than a temporary object, or
- an expression that is not a subexpression of another expression and that is not otherwise part of a full-expression.
For an initializer, performing the initialization of the entity (including evaluating default member initializers of an aggregate) is also considered part of the full-expression.
项目符号 3 说 s1 = 1
是一个完整表达式,因为它是一个初始化声明符,而 I(i)
是一个完整表达式,因为它是一个 mem-initializer
并且对于 D(i)
。这意味着初始化实体 s1
可以包含多个完整表达式?在这种情况下,这组全表达式中初始化的全表达式是哪个?
当然,完整表达式可以动态嵌套:考虑
void f(int i) {
++i; // (useless) full-expression
}
void g() {
f(1); // full-expression
}
因此,初始化 s1
是 init-declarator 完整表达式的一部分,同时还包含其 [=16= 的完整表达式之间没有冲突]内存初始化器s.