[clang] [clang] pointer to member with qualified-id enclosed in parentheses in unevaluated context should be invalid (PR #89713)

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 24 20:57:21 PDT 2024


================
@@ -27,3 +26,20 @@ namespace rdar10544564 {
   X (Y::*func_mem_ptr1)() = &Y::memfunc1;
   X (Y::*func_mem_ptr2)() = &Y::memfunc2;
 }
+
+namespace test2 {
+  struct A {
+    int val;
+    void func() {}
+  };
+
+  void test() {
+    decltype(&(A::val)) ptr1; // expected-error {{invalid use of non-static data member 'val'}}
+    int A::* ptr2 = &(A::val); // expected-error {{invalid use of non-static data member 'val'}}
+
+    // FIXME: Error messages in these cases are less than clear, we can do
+    // better.
+    int size = sizeof(&(A::func)); // expected-error {{call to non-static member function without an object argument}}
+    void (A::* ptr3)() = &(A::func); // expected-error {{call to non-static member function without an object argument}}
----------------
zwuis wrote:

> I would expect `err_invalid_non_static_member_use` to be used there too (or rather, that case should be consistent with above)

This inconsistency is irrelevant to PR 40906. I am confused about the following questions:

1. Do I need to remove these tests?
2. Do I need to fix this inconsistency in this PR, or a new PR?
3. Should I open an issue for it?

https://github.com/llvm/llvm-project/pull/89713


More information about the cfe-commits mailing list