From: Anders Carlsson Date: Thu, 15 Oct 2009 00:41:48 +0000 (+0000) Subject: Check the return type when calling pointer to member functions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d6d90d5499d4248761251811ebed0ae77665ed7;p=clang Check the return type when calling pointer to member functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84161 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index d8e49c7d69..a946500660 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2917,15 +2917,18 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, if (BO->getOpcode() == BinaryOperator::PtrMemD || BO->getOpcode() == BinaryOperator::PtrMemI) { const FunctionProtoType *FPT = cast(BO->getType()); - QualType ReturnTy = FPT->getResultType(); + QualType ResultTy = FPT->getResultType().getNonReferenceType(); - CXXMemberCallExpr *CE = - new (Context) CXXMemberCallExpr(Context, BO, Args, NumArgs, - ReturnTy.getNonReferenceType(), - RParenLoc); - - ExprOwningPtr TheCall(this, CE); + ExprOwningPtr + TheCall(this, new (Context) CXXMemberCallExpr(Context, BO, Args, + NumArgs, ResultTy, + RParenLoc)); + if (CheckCallReturnType(FPT->getResultType(), + BO->getRHS()->getSourceRange().getBegin(), + TheCall.get(), 0)) + return ExprError(); + if (ConvertArgumentsForCall(&*TheCall, BO, 0, FPT, Args, NumArgs, RParenLoc)) return ExprError(); diff --git a/test/SemaCXX/incomplete-call.cpp b/test/SemaCXX/incomplete-call.cpp index 6134189f0a..08bfdefd62 100644 --- a/test/SemaCXX/incomplete-call.cpp +++ b/test/SemaCXX/incomplete-call.cpp @@ -1,5 +1,5 @@ // RUN: clang-cc -fsyntax-only -verify %s -struct A; // expected-note 13 {{forward declaration of 'struct A'}} +struct A; // expected-note 14 {{forward declaration of 'struct A'}} A f(); // expected-note {{note: 'f' declared here}} @@ -35,4 +35,8 @@ void g() { b[0]; // expected-error {{calling 'operator[]' with incomplete return type 'struct A'}} b + 1; // expected-error {{calling 'operator+' with incomplete return type 'struct A'}} b->f(); // expected-error {{calling 'operator->' with incomplete return type 'struct A'}} + + A (B::*mfp)() = 0; + (b.*mfp)(); // expected-error {{calling function with incomplete return type 'struct A'}} + }