overload resolution failed

131 views
Skip to first unread message

Krzysztof Żelechowski

unread,
Aug 5, 2013, 2:20:32 AM8/5/13
to

Given the following declarations:

int f (int *), f (int);

what does the expression (f (01)) evaluate to?

1. It is an unqualified function call.

2. The name is looked up and the result is ::f.

3. The set of function declarations returned by the lookup depends on your
interpretation.

3a. Under a strict interpretation, since the lookup finds a set of fully
qualified function *names*, the set of function *declarations* returned is
empty and the expression (f (01)) is ill-formed.

3b. Under a permissive interpretation, we could take into account that
function names are introduced by declarations and consider the declarations
corresponding to the function names found by the lookup. But the lookup
stops as soon as it finds the name declared, that means it considers only
the declaration ::f (int *) and it would return that one. In that case, the
expression (f (01)) is ill-formed too.

The expression would be well-formed if the standard allowed to consider all
declarations for the function names found by the lookup, which is currently
not the case.


--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp...@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

Bart van Ingen Schenau

unread,
Aug 6, 2013, 3:51:35 AM8/6/13
to

On Mon, 05 Aug 2013 00:20:32 -0600, Krzysztof Żelechowski wrote:

> Given the following declarations:
>
> int f (int *), f (int);
>
> what does the expression (f (01)) evaluate to?
>
> 1. It is an unqualified function call.
>
> 2. The name is looked up and the result is ::f.
>
> 3. The set of function declarations returned by the lookup depends on
> your interpretation.
>
> 3a. Under a strict interpretation, since the lookup finds a set of fully
> qualified function *names*, the set of function *declarations* returned
> is empty and the expression (f (01)) is ill-formed.

This interpretation is incorrect.
The expression `f (01)` is parsed as a `/postfix-expression/ ( /optional-
expression-list/ )`, with the additional constraint that the postfix-
expression must be an lvalue referring to a function or have pointer to
function type.
The name lookup finds the name ::f, which perfect qualifies as an lvalue
referring to a function, because ::f was declared as being the name of a
function.

In the following overload resolution, the set of overload declarations
for the found name(s) is built. If a function name was found, this set
can never be empty.

>
> 3b. Under a permissive interpretation, we could take into account that
> function names are introduced by declarations and consider the
> declarations corresponding to the function names found by the lookup.
> But the lookup stops as soon as it finds the name declared, that means
> it considers only the declaration ::f (int *) and it would return that
> one. In that case, the expression (f (01)) is ill-formed too.

The name-lookup stops as soon as the first declaration is found, but the
rules for overload resolution (C++ 03 13.3.1.1.1/3 [over.call.func])
require that *all* overloaded declarations are used in the resolution. If
needed, the compiler must make an additional search for overloads in the
same scope as the found declaration to satisfy that requirement.

>
> The expression would be well-formed if the standard allowed to consider
> all declarations for the function names found by the lookup, which is
> currently not the case.

It is already required (and your expression is well-formed, calling int f
(int)).

Bart v Ingen Schenau

Křištof Želechovski

unread,
Jan 6, 2014, 3:36:40 PM1/6/14
to
Bart van Ingen Schenau wrote:

>
> On Mon, 05 Aug 2013 00:20:32 -0600, Krzysztof Żelechowski wrote:
>
>> Given the following declarations:
>>
>> int f (int *), f (int);
>>
>> what does the expression (f (01)) evaluate to?
>>
>> 1. It is an unqualified function call.
>>
>> 2. The name is looked up and the result is ::f.
>>
>> 3. The set of function declarations returned by the lookup depends on
>> your interpretation.
>>
>> 3a. Under a strict interpretation, since the lookup finds a set of fully
>> qualified function *names*, the set of function *declarations* returned
>> is empty and the expression (f (01)) is ill-formed.
>
> This interpretation is incorrect.
> The expression `f (01)` is parsed as a `/postfix-expression/ ( /optional-
> expression-list/ )`, with the additional constraint that the postfix-
> expression must be an lvalue referring to a function or have pointer to
> function type.
> The name lookup finds the name ::f, which perfect qualifies as an lvalue
> referring to a function, because ::f was declared as being the name of a
> function.
>
> In the following overload resolution, the set of overload declarations
> for the found name(s) is built.

But the Standard does not mention this step; it just says that the lookup
returns the set of declarations, which is inconsistent with the description
of the lookup.
Reply all
Reply to author
Forward
0 new messages