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.
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