N4140 中 §8.2[dcl.ambig.res]/2 中的注释

Note in §8.2[dcl.ambig.res]/2 in N4140

§8.2[dcl.ambig.res]/2 中我们有以下注释(重点是我的):

[ Note: A declaration can be explicitly disambiguated by a nonfunction-style cast, by an = to indicate initialization or by removing the redundant parentheses around the parameter name. —end note ]

不应该是插入而不是上面的删除吗?

考虑以下示例:

#include <iostream>
struct S{ int i; S(int j) : i(j) {} };
float f = 1.0f;

S s(int(f)); // function declaration

int main()
{
    std::cout << s.i << '\n';
}

代码无法编译,因为编译器将声明 S s(int(f)); 视为函数声明。但是如果我们确实在参数名称 f 周围插入括号,如 S s((int(f))); 代码编译并打印 1.

我不得不同意 Simple 的评论,它告诉你参数名称周围的括号是多余的。 defect report 340: Unclear wording in disambiguation section 已作为非缺陷关闭,并给出了以下示例:

加强了这一点
  struct Point
  {
    Point(int){}
  };
  struct Lattice 
  {
    Lattice(Point, Point, int){}
  };
  int main(void)
  {
    int a, b;
    Lattice latt(Point(a), Point(b), 3);   /* Line X */
  }

并说:

The declaration of latt declares a function with a return value of the type Lattice and taking three arguments. The type of the first two arguments is Point and each of these arguments is followed by a parameter name in redundant parentheses. The type of the third argument can not be determined, because it is a literal. This will result in a syntax error.

我同意Belloc的观点。注释本可以用以下更改(粗体)来编写,以赋予它更准确的含义,在这种情况下,单词 remove 没有意义。

对象 声明可以通过非函数式强制转换、= 指示初始化或通过 删除 在参数名称两边插入 多余的括号。 —尾注