C++ Logo

std-discussion

Advanced search

Does [expr.call]/1 correctly authorize the snippet below to compile?

From: J.A. Belloc <jabelloc_at_[hidden]>
Date: Thu, 10 Oct 2019 10:08:21 -0300
[expr.call]/1 <http://eel.is/c++draft/expr.call#1> (emphasis is mine):

A function call is a postfix expression followed by parentheses containing
> a possibly empty, comma-separated list of *initializer-clause
> <http://eel.is/c++draft/dcl.init#nt:initializer-clause>*s which
> constitute the arguments to the function.
> <http://eel.is/c++draft/expr.call#1.sentence-1>


> The postfix expression shall have function type or function pointer type.
> <http://eel.is/c++draft/expr.call#1.sentence-2>
>
> For a call to a non-member function or to a static member function, the
> postfix expression shall either be an lvalue that refers to a function (in
> which case the function-to-pointer standard conversion ([conv.func]
> <http://eel.is/c++draft/conv.func>) is suppressed on the postfix
> expression), or *have function pointer type*.
> <http://eel.is/c++draft/expr.call#1.sentence-3>
>


My impression reading this paragraph is that the sentence "have a function
pointer type" is referring to an lvalue having function to pointer type,
not to a prvalue obtained from a function call returning a pointer to
function.

Thus, I don't think [expr.call]/1 correctlly allows the following snippet
to compile (demo <http://coliru.stacked-crooked.com/a/c4a74e9721c05b48>):

#include<iostream>

void f(int a) {
    std::cout << "f(" << a << ")\n";
}

// g is a function of () returning a pointer to a function of (int)
returning void

void(*g())(int) {
    return f; // f is function of (int) returning void.
}

int main()
{
   g()(1); // The expression g() has type pointer to function, but is a
prvalue.
}


-- 
Belloc

Received on 2019-10-10 08:10:46