C++11标准中§12.6.2/2中单词"constructor's class"的解释

Interpretation of the words "constructor's class" in §12.6.2/2 in the C++11 Standard

作为健全性检查,有人可以确认 §12.6.2/2 中的 constructor's class 一词是否指的是委托构造函数吗?

12.6.2/2 声明:

Unless the mem-initializer-id names the constructor’s class, a non-static data member of the constructor’s class, or a direct or virtual base of that class, the mem-initializer is ill-formed.

是的。它表示与 mem-initializer-id 具有相同的 class 是有效的,这将使当前构造函数成为委托构造函数。这在 12.6.2/6 中有进一步解释:

If a mem-initializer-id designates the constructor’s class, it shall be the only mem-initializer; the constructor is a delegating constructor, and the constructor selected by the mem-initializer is the target constructor.

他们有。来自 delegating constructors proposal:

Change §12.6.2(2) as follows:

(...) Unless the mem-initializer-id names a non-static data member of the constructor's class, the constructor's class, or a a direct or virtual base of that class, the mem-initializer is ill-formed. (...)

新插入的文本在提案中用下划线代替了粗体,但我不能在 markdown 中这样做。它继续下去:

A mem-initializer-list can delegate to another constructor (the target constructor) of the constructor's class using any name that denotes the constructor's class itself. (...)

此措辞在最终标准 12.6.2 (6) 中发现,稍有改动:

A mem-initializer-list can delegate to another constructor of the constructor's class using any class-or-decltype that denotes the constructor's class itself. (...)

所以是的,所有这些都来自委派构造函数的提案,并且专门指构造函数委托。

在整个 [class.base.init] 中,"constructor" 指的是第 1 段中介绍的相同 "constructor":

In the definition of a constructor for a class, initializers for direct and virtual base subobjects and non-static data members can be specified by a ctor-initializer, which has the form [...]

第2段说在a构造函数的定义中,mem-initializer-id(可以有多个mem-initializer-ids in a mem-initializer-list) 可以指三件事之一:

  • 构造函数的class,即委托构造函数(第6段)
  • 一个非静态数据成员,即S() : n{5}
  • class 的直接或虚拟基础,即 S() : Base(5)(第 3 段)