[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


================
@@ -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();
+            return QualType();
----------------
cor3ntin wrote:

Continuing might lead to better error recovery here

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


More information about the cfe-commits mailing list