zwuis wrote:

These changes pass all tests above:

```diff
-if (isa<DeclRefExpr>(op) && cast<DeclRefExpr>(op)->getQualifier()) {
+if (isa<DeclRefExpr>(op) && cast<DeclRefExpr>(op)->getQualifier() &&
+    !isa<ParenExpr>(OrigOp.get())) {
   DeclContext *Ctx = dcl->getDeclContext();
   if (Ctx && Ctx->isRecord()) {
     if (dcl->getType()->isReferenceType()) {
       Diag(OpLoc,
             diag::err_cannot_form_pointer_to_member_of_reference_type)
         << dcl->getDeclName() << dcl->getType();
       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())) {
-      SourceLocation LeftParenLoc = OrigOp.get()->getBeginLoc(),
-                      RightParenLoc = OrigOp.get()->getEndLoc();
-
-      Diag(LeftParenLoc,
-            diag::err_form_ptr_to_member_from_parenthesized_expr)
-          << SourceRange(OpLoc, RightParenLoc)
-          << FixItHint::CreateRemoval(LeftParenLoc)
-          << FixItHint::CreateRemoval(RightParenLoc);
-
-      // Continuing might lead to better error recovery.
-    }
 
     while (cast<RecordDecl>(Ctx)->isAnonymousStructOrUnion())
       Ctx = Ctx->getParent();
 
     QualType MPTy = Context.getMemberPointerType(
         op->getType(),
         Context.getTypeDeclType(cast<RecordDecl>(Ctx)).getTypePtr());
     // Under the MS ABI, lock down the inheritance model now.
     if (Context.getTargetInfo().getCXXABI().isMicrosoft())
       (void)isCompleteType(OpLoc, MPTy);
     return MPTy;
   }
 }
```

PS: Sorry for misunderstanding the original issue.

https://github.com/llvm/llvm-project/pull/89713
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to