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

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

There are two types of function calls: ordinary function calls and member function calls (9.3). A function call is a postfix expression, followed by parentheses containing perhaps an empty list of expressions, separated by commas, that make up the arguments to the function. For a regular function call, the postfix expression must be either an lvalue that refers to the function (in this case, the standard conversion of the-to-pointer function (4.3) is suppressed in the postfix expression), or it must have a pointer to the type of the function .

Edit

Basically, I ask: when does the standard say "(in this case, the standard function-to-pointer transformation is suppressed in a postfix expression)" does this mean that this suppression is good or that it will be canceled later (for example, after function overloading )?

Edit1

In my opinion, the word “suppressed” above is misleading, as it seems that the conversion from the function name to the function pointer will never be performed by the compiler. I believe that this is not so. This conversion will always occur after the function overload process is completed, because only at this moment the compiler knows exactly which function to call. This is not the case when a program initializes a function pointer. In this situation, the compiler knows the function being called, so there will be no overload, as shown in the example below.

#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

+6
source share
2 answers

For a regular function call, the postfix expression must be either an lvalue that refers to the function (in this case, the standard conversion of the-to-pointer function (4.3) is suppressed in the postfix expression) or it must have a pointer to the type of the function.

So, the "postfix expression" is defined in 5.2 / 1 ... this is not necessarily a grammatical element, which means the type of " x++ " postfix ... look at the list itself. Basically, the fact is that there is an expression that:

  • "there must be either an lvalue that refers to the function (in this case, the standard conversion of the-to-pointer function (4.3) is suppressed in a postfix expression)"

This means that the expression is actually an identifier for the function or something like (x ? fn1 : fn2) . It does not need to be converted to a pointer - the compiler already knows how to call the function.

(The reason that it should not be converted is the priority of the operator - in particular, the suffix ++ and -- , () for function calls [] And -> all have the same priority and associativity from left to right, therefore, for example , [1]f(1,2,3) considered as [1](f(1,2,3)) , because this is the only match of the parsing, whereas if decomposition into a pointer occurs, associativity from left to right will consider it like ([1]f)(1,2,3) .)

  • "or it must have a pointer to the type of function."

So you can also point to a function pointer.

+8
source

The absence of any statements in the Standard to the contrary, suppression, apparently, is constant. I think the conversion is suppressed because (i) overload resolution is required, and (ii) this situation is not necessary. In fact, it would be impossible to convert to a pointer before we knew exactly which function was being called. After resolving the overload, we know that we directly call the function, so the conversion will be pointless.

+1
source

All Articles