2

In §8.2[dcl.ambig.res]/2 we have the following note (emphases is mine):

[ 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 ]

Shouldn't it be inserting instead of removing above?

Consider the following example:

#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';
}

The code doesn't compile, as the compiler considers the declaration S s(int(f)); as a function declaration. But if we do insert the parenthesis around the parameter name f, like S s((int(f))); the code compiles and prints 1.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
Belloc
  • 6,318
  • 3
  • 22
  • 52
  • 4
    It's trying to say that if you did intend to define a function, you shouldn't put parentheses around the parameter name. – Simple Oct 23 '15 at 11:47
  • I think it should say "removing". Taking the ambiguous definition `S s(int(f));`: inserting parentheses would give `S s(int((f)));` which is still ambiguous. However removing parentheses gives `S s(int f);` which is not ambiguous. – M.M Nov 05 '15 at 22:08

2 Answers2

1

I have to agree with Simple's comment, it is telling you that the parentheses around the parameter name is redundant. This is reinforced by defect report 340: Unclear wording in disambiguation section which was closed as Not A Defect and gives the following example:

  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 */
  }

and says:

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.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
  • The text you quoted just seems wrong to me. (It was written by the submitter of this rejected proposal). `Lattice latt(Point(a), Point(b), 3);` cannot be a function declaration because of the `3`, therefore it is an object declaration. Current compilers accept this code. – M.M Nov 05 '15 at 22:04
-1

I agree with Belloc's argument. The Note could have been written with the following change (in bold) to give it a more precise meaning, an in this case the word remove doesn't make sense.

An object declaration can be explicitly disambiguated by a nonfunction-style cast, by an = to indicate initialization or by removing inserting the redundant parentheses around the parameter name. —end note

Community
  • 1
  • 1
Leon
  • 868
  • 4
  • 12
  • This would be incorrect though. Inserting redundant parentheses on an ambiguous declaration still results in an ambiguous declaration. (which declares a function). – M.M Nov 05 '15 at 22:12
  • Also, an ambiguous declaration is a function declaration, so "an object declaration" would exclude ambiguous declarations. I guess you mean "An ambiguous declaration which is intended to declare an object can be explicitly disambiguated by..." – M.M Nov 05 '15 at 22:12