[cfe-commits] r84043 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp lib/Sema/SemaOverload.cpp test/SemaCXX/incomplete-call.cpp
Anders Carlsson
andersca at mac.com
Tue Oct 13 15:43:21 PDT 2009
Author: andersca
Date: Tue Oct 13 17:43:21 2009
New Revision: 84043
URL: http://llvm.org/viewvc/llvm-project?rev=84043&view=rev
Log:
Check the return type of binary operators and the arrow operator.
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaCXX/incomplete-call.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=84043&r1=84042&r2=84043&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Oct 13 17:43:21 2009
@@ -1993,7 +1993,7 @@
CTypes.insert(Context.getCanonicalType(BaseType));
while (BaseType->isRecordType()) {
- Base = BuildOverloadedArrowExpr(S, move(Base), BaseExpr->getExprLoc());
+ Base = BuildOverloadedArrowExpr(S, move(Base), OpLoc);
BaseExpr = (Expr*)Base.get();
if (BaseExpr == NULL)
return ExprError();
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=84043&r1=84042&r2=84043&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Oct 13 17:43:21 2009
@@ -4698,9 +4698,16 @@
OpLoc);
UsualUnaryConversions(FnExpr);
- Expr *CE = new (Context) CXXOperatorCallExpr(Context, Op, FnExpr,
- Args, 2, ResultTy, OpLoc);
- return MaybeBindToTemporary(CE);
+ ExprOwningPtr<CXXOperatorCallExpr>
+ TheCall(this, new (Context) CXXOperatorCallExpr(Context, Op, FnExpr,
+ Args, 2, ResultTy,
+ OpLoc));
+
+ if (CheckCallReturnType(FnDecl->getResultType(), OpLoc, TheCall.get(),
+ FnDecl))
+ return ExprError();
+
+ return MaybeBindToTemporary(TheCall.release());
} else {
// We matched a built-in operator. Convert the arguments, then
// break out so that we will build the appropriate built-in
@@ -5171,10 +5178,16 @@
Expr *FnExpr = new (Context) DeclRefExpr(Method, Method->getType(),
SourceLocation());
UsualUnaryConversions(FnExpr);
- Base = new (Context) CXXOperatorCallExpr(Context, OO_Arrow, FnExpr, &Base, 1,
- Method->getResultType().getNonReferenceType(),
- Method->getLocation());
- return Owned(Base);
+
+ QualType ResultTy = Method->getResultType().getNonReferenceType();
+ ExprOwningPtr<CXXOperatorCallExpr>
+ TheCall(this, new (Context) CXXOperatorCallExpr(Context, OO_Arrow, FnExpr,
+ &Base, 1, ResultTy, OpLoc));
+
+ if (CheckCallReturnType(Method->getResultType(), OpLoc, TheCall.get(),
+ Method))
+ return ExprError();
+ return move(TheCall);
}
/// FixOverloadedFunctionReference - E is an expression that refers to
Modified: cfe/trunk/test/SemaCXX/incomplete-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/incomplete-call.cpp?rev=84043&r1=84042&r2=84043&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/incomplete-call.cpp (original)
+++ cfe/trunk/test/SemaCXX/incomplete-call.cpp Tue Oct 13 17:43:21 2009
@@ -1,5 +1,5 @@
// RUN: clang-cc -fsyntax-only -verify %s
-struct A; // expected-note 11 {{forward declaration of 'struct A'}}
+struct A; // expected-note 13 {{forward declaration of 'struct A'}}
A f(); // expected-note {{note: 'f' declared here}}
@@ -10,6 +10,8 @@
A operator!(); // expected-note 2 {{'operator!' declared here}}
A operator++(int); // expected-note {{'operator++' declared here}}
A operator[](int); // expected-note {{'operator[]' declared here}}
+ A operator+(int); // expected-note {{'operator+' declared here}}
+ A operator->(); // expected-note {{'operator->' declared here}}
};
void g() {
@@ -31,4 +33,6 @@
b(); // expected-error {{calling 'operator()' with incomplete return type 'struct A'}}
b++; // expected-error {{calling 'operator++' with incomplete return type 'struct A'}}
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'}}
}
More information about the cfe-commits
mailing list