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

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 23 02:08:09 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}}
----------------
cor3ntin wrote:

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

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


More information about the cfe-commits mailing list