https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82791

            Bug ID: 82791
           Summary: Inconsistency with member function pointer access
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: contact at lngnslnvsk dot net
  Target Milestone: ---

Consider this code:

#include <typeinfo>
struct Foo
{
    void Bar();
};
int main()
{
    Foo obj;
    auto mfp = &Foo::Bar;

    auto foo = typeid(obj.*mfp).name(); //returns "void ()"
    auto bar = (void(*)(void)) (obj.*mfp); //cast succeeds
    auto baz = sizeof(obj.*mfp); //returns 1

    decltype(obj.*mfp) qux; //does not compile
    auto quux = obj.*mfp; //cannot deduce type
}

Compilation fails with the messages "error: invalid use of non-static member
function of type 'void (Foo::)()'" and "error: unable to deduce 'auto' from
'obj.*mfp'" while all other expressions succeed with only casting and sizeof
generating warnings.
"Noexcept" also succeeds, and probably other operators I did not test.

Both Clang and Zapcc reject the whole program.
ICC rejects everything except the cast.
MSVC rejects everything except the access in typeid and noexcept.

This does not follow N4700 ยง8.5.6 "If the result of .* or ->* is a function,
then that result can be used only as the operand for the function call
operator ()."
But if we ignore this, this looks like an inconsistency that could be solved by
authorizing 'auto' and 'decltype' to deduce "void(*)(void)", aligning with
'typeid'.
I don't understand what 'sizeof' does in this case so I won't comment on that.

Reply via email to