llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.71k stars 10.94k forks source link

[clang][diagnostics] diagnostics can be more clear when forming pointer to member from parenthesized expression #90822

Open zwuis opened 2 months ago

zwuis commented 2 months ago
struct foo {
    int val;
    void func() {}
};

int main() {
    int foo::* ptr1 = &(foo::val);
    void (foo::* ptr2)() = &(foo::func);
}

Diagnostic messages of this code are "invalid use of non-static data member 'val'" (line 6) and "call to non-static member function without an object argument" (line 7). (clang 18.1.0, https://godbolt.org/z/YhGvWrTTb)

These messages can be more clear like "cannot form pointer to member from a parenthesized expression".

llvmbot commented 2 months ago

@llvm/issue-subscribers-clang-frontend

Author: YanzuoLiu (zwuis)

```cpp struct foo { int val; void func() {} }; int main() { int foo::* ptr1 = &(foo::val); void (foo::* ptr2)() = &(foo::func); } ``` Diagnostic messages of this code are "invalid use of non-static data member 'val'" (line 6) and "call to non-static member function without an object argument" (line 7). (clang 18.1.0, <https://godbolt.org/z/YhGvWrTTb>) These messages can be more clear like "cannot form pointer to member from a parenthesized expression".
zwuis commented 1 week ago

I think it's difficult to implement now.

Consider this code:

int foo::* ptr = &(foo::val + 1);