Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of this statement in the C++11 Standard?

What do the characters in bold mean in this sentence extracted from paragraph §5.2.2/1 of the C++11 Standard?

There are two kinds of function call: ordinary function call and member function (9.3) call. A function call is a postfix expression followed by parentheses containing a possibly empty, comma-separated list of expressions which constitute the arguments to the function. For an ordinary function call, the postfix expression shall be either an lvalue that refers to a function (in which case the function-to-pointer standard conversion (4.3) is suppressed on the postfix expression), or it shall have pointer to function type.

Edit

Basically what I'm asking is: when the Standard says "(in which case the function-to-pointer standard conversion is suppressed on the postfix expression)" does it mean that this suppression is for good or that it will be revoked later (e.g. after function overloading)?

Edit1

In my opinion the word "suppressed" above is misleading since it gives the impression that the conversion from function name to a function pointer might never be done by the compiler. I believe that's not the case. This conversion will always occur after the function overloading process is finished, since only at this point, the compiler knows exactly which function to call. That's not the case when the program initializes a function pointer. In this situation, the compiler knows the function to be called, so there will be no overloading, as the example below shows.

#include <iostream>
int foo(int i) { std::cout << "int" << '\n'; return i * i; }
double foo(double d) { std::cout << "double" << '\n'; return d * d; }

int main()
{
    int(*pf)(int) = foo;                //  no overloading here!
    std::cout << pf(10.) << '\n';       //  calls foo(int)
    std::cout << foo(10.) << '\n';      //  call foo(double) after function overloading. Therefore, only after function
                                        //  overloading is finished, the function name foo() is converted into a function-pointer.
}

The code prints:

int
100
double
100

like image 294
Wake up Brazil Avatar asked Mar 19 '14 01:03

Wake up Brazil


1 Answers

Absent any statement in the Standard to the contrary, the suppression is presumably permanent. I think the conversion is suppressed because (i) overload resolution needs to take place and (ii) it is not necessary in this situation. Indeed, it would be impossible to convert to a pointer before we knew exactly which function is being called. After overload resolution, we know we are directly calling the function, so a conversion would be pointless.

like image 50
Eric M Schmidt Avatar answered Oct 20 '22 00:10

Eric M Schmidt