[cfe-commits] r83268 - /cfe/trunk/lib/Sema/SemaExpr.cpp
Douglas Gregor
dgregor at apple.com
Mon Oct 5 15:57:50 PDT 2009
On Oct 3, 2009, at 10:40 AM, Anders Carlsson wrote:
> Author: andersca
> Date: Sat Oct 3 12:40:22 2009
> New Revision: 83268
>
> URL: http://llvm.org/viewvc/llvm-project?rev=83268&view=rev
> Log:
> Create CXXMemberCallExpr for pointer-to-member calls.
>
> Modified:
> cfe/trunk/lib/Sema/SemaExpr.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=83268&r1=83267&r2=83268&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Oct 3 12:40:22 2009
> @@ -2902,6 +2902,28 @@
> return Owned(BuildCallToMemberFunction(S, Fn, LParenLoc,
> Args, NumArgs,
> CommaLocs, RParenLoc));
> }
> +
> + // Determine whether this is a call to a pointer-to-member
> function.
> + if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Fn-
> >IgnoreParens())) {
> + if (BO->getOpcode() == BinaryOperator::PtrMemD ||
> + BO->getOpcode() == BinaryOperator::PtrMemI) {
> + const FunctionProtoType *FPT = cast<FunctionProtoType>(BO-
> >getType());
> + QualType ReturnTy = FPT->getResultType();
> +
> + CXXMemberCallExpr *CE =
> + new (Context) CXXMemberCallExpr(Context, BO, Args, NumArgs,
> +
> ReturnTy.getNonReferenceType(),
> + RParenLoc);
> +
> + ExprOwningPtr<CXXMemberCallExpr> TheCall(this, CE);
> +
> + if (ConvertArgumentsForCall(&*TheCall, BO, 0, FPT, Args,
> NumArgs,
> + RParenLoc))
> + return ExprError();
> +
> + return Owned(MaybeBindToTemporary(TheCall.release()).release
> ());
> + }
> + }
> }
I think there's more work to be done either here or in
CheckPointerToMemberOperands, because we need to make sure that the
object argument is properly upcasted. For example, given:
class Base {
public:
void f() const;
};
class Derived : public Base {
};
void f(Derived *d) {
void (Base::*mfp)() const = &Base::f;
(d->*mfp)();
}
-ast-dump produces:
(CXXMemberCallExpr 0x32059c0 <line:11:4, col:13> 'void'
(BinaryOperator 0x3205a00 <col:4, col:8> 'void (void)' '->*'
(DeclRefExpr 0x3205850 <col:4> 'class Derived *' ParmVar='d'
0x3205750)
(DeclRefExpr 0x3205870 <col:8> 'void (class Base::*)(void)'
Var='mfp' 0x3205700))))
so we're missing both the derived-to-base conversion and the
conversion that adds "const" to the object argument.
- Doug
More information about the cfe-commits
mailing list