[cfe-dev] Parse error for addrof overloaded function.

Richard Smith richard at metafoo.co.uk
Thu Jul 25 11:46:49 PDT 2013


On Thu, Jul 25, 2013 at 1:49 AM, Enea Zaffanella <zaffanella at cs.unipr.it>wrote:

> Hello Richard,
>
> I am afraid there is still something unclear to me
> (I may be missing something obvious ...):
>
>
> On 07/23/2013 11:13 PM, Richard Smith wrote:
>
>> On Tue, Jul 23, 2013 at 1:30 PM, Enea Zaffanella <zaffanella at cs.unipr.it
>> <mailto:zaffanella at cs.unipr.it**>> wrote:
>>
>>     Hello.
>>
>>     When parsing the following program:
>>     ==============================**__=====
>>
>>     $ cat addrof-overloaded.cc
>>     struct S {
>>        static void foo(int);
>>        static void foo(double);
>>     } s;
>>
>>     typedef void (*PF)(int);
>>
>>     void test() {
>>        PF pf1 = s.foo;   // No error.
>>        PF pf2 = &s.foo;  // Error(?)
>>     }
>>     ==============================**__=====
>>
>>
>>     the following parse error is obtained:
>>     ==============================**__=====
>>
>>     $ clang++ -fsyntax-only addrof-overloaded.cc
>>     addrof-overloaded.cc:10:12: error: cannot create a non-constant
>>     pointer to
>>            member function
>>        PF pf2 = &s.foo;  // Error(?)
>>                 ^~~~~~
>>     1 error generated.
>>     ==============================**__=====
>>
>>
>>     Is this a known bug?
>>
>>
>> It's not a bug. You can't do that.
>> http://www.open-std.org/jtc1/**sc22/wg21/docs/cwg_closed.**html#61<http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#61>
>>
>
> Why isn't clang issuing a similar diagnostics for the first line:
>
>
> >        PF pf1 = s.foo;   // No error.
>
> Reading 13.4 in the C++03 standard, there seems to be no distinction of
> whether or not the address-of operator is explicitly used (it is meant, for
> non-instance methods):
>
> ===================
> A use of an overloaded function name without arguments is resolved in
> certain contexts to a function, a pointer to function or a pointer to
> member function for a specific function from the overload set.
> [...]
> The overloaded function name can be preceded by the & operator. An
> overloaded function name shall not be used without arguments in contexts
> other than those listed.
> ===================
>
> Which is the bit of the standard saying that the thing is legal if the `&'
> is left implicit?
>

Hmm, I missed that part of your question. I think that is a bug; we should
reject both examples.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130725/512bc304/attachment.html>


More information about the cfe-dev mailing list