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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 23 05:19:03 PDT 2024


================
@@ -14644,6 +14644,17 @@ QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc) {
             return QualType();
           }
 
+          // C++11 [expr.unary.op] p4:
+          // A pointer to member is only formed when an explicit & is used and
+          // its operand is a qualified-id not enclosed in parentheses.
+          if (isa<ParenExpr>(OrigOp.get())) {
+            // `op->getEndLoc()` is the last part of the qualified-id.
+            // For example, "baz" in "foo::bar::baz".
+            Diag(op->getEndLoc(), diag::err_invalid_non_static_member_use)
+                << dcl->getDeclName() << op->getSourceRange();
----------------
AaronBallman wrote:

We should also add a fix-it to remove the parentheses as a kindness to the user.

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


More information about the cfe-commits mailing list