Skip to content

clang could help more when calling pointer-to-member function #11187

@llvmbot

Description

@llvmbot
Bugzilla Link 10815
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor

Extended Description

This invalid program gives a diagnostic that could be better:

struct X { void foo(); };
void t() {
  X x;
  void (X::*y)() = &X::foo;
  x.*y();
}

These member-pointer things are hard (though fortunately rare), so a good compiler diagnostic would be really helpful. The error is:

x.cc:6:7: error: called object type 'void (X::*)()' is not a function or
      function pointer
  x.*y();
     ~^

while gcc gives me this:

x.cc: In function ‘void t()’:
x.cc:6: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘y (...)’, e.g. ‘(... ->* y) (...)’

which actually showed me that I needed to insert the parens. Nice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions