[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
Fri Jul 19 16:56:14 PDT 2024
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
More information about the cfe-commits
mailing list