]> granicus.if.org Git - clang/commitdiff
Check the return type of binary operators and the arrow operator.
authorAnders Carlsson <andersca@mac.com>
Tue, 13 Oct 2009 22:43:21 +0000 (22:43 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 13 Oct 2009 22:43:21 +0000 (22:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84043 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
lib/Sema/SemaOverload.cpp
test/SemaCXX/incomplete-call.cpp

index 5a40fc83c55d80c61922effc0ef10150f3d1dce3..8a67d479543803dfc8f628352055eb946dffeac8 100644 (file)
@@ -1993,7 +1993,7 @@ Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc,
     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();
index 7b79fa5f4af9605e1851d8bab30772f48393d881..8c697cc86882a54ae534f99699cfb86686dd41a4 100644 (file)
@@ -4698,9 +4698,16 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
                                                  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 @@ Sema::BuildOverloadedArrowExpr(Scope *S, ExprArg BaseIn, SourceLocation OpLoc) {
   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
index 4decd864832af8cd99e098930dd5e30777145151..6134189f0a9aa7bc0af4ba82551ce14d4cc3b6be 100644 (file)
@@ -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 @@ struct B {
   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 @@ void g() {
   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'}}
 }