]> granicus.if.org Git - clang/commitdiff
More return type checking.
authorAnders Carlsson <andersca@mac.com>
Tue, 13 Oct 2009 21:49:31 +0000 (21:49 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 13 Oct 2009 21:49:31 +0000 (21:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84034 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 194317ce237e54cbe4ccb4469f4b4daba0523d7b..56dd67023330eb607645bd9eda693b8ceba9574a 100644 (file)
@@ -1572,9 +1572,7 @@ Sema::ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
         }
 
         // Determine the result type
-        QualType ResultTy
-          = FnDecl->getType()->getAs<FunctionType>()->getResultType();
-        ResultTy = ResultTy.getNonReferenceType();
+        QualType ResultTy = FnDecl->getResultType().getNonReferenceType();
 
         // Build the actual expression node.
         Expr *FnExpr = new (Context) DeclRefExpr(FnDecl, FnDecl->getType(),
@@ -1583,9 +1581,15 @@ Sema::ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
 
         Input.release();
         Args[0] = Arg;
-        return Owned(new (Context) CXXOperatorCallExpr(Context, OverOp, FnExpr,
-                                                       Args, 2, ResultTy,
-                                                       OpLoc));
+        
+        ExprOwningPtr<CXXOperatorCallExpr> 
+          TheCall(this, new (Context) CXXOperatorCallExpr(Context, OverOp, 
+                                                          FnExpr, Args, 2, 
+                                                          ResultTy, OpLoc));
+        
+        if (CheckCallReturnType(FnDecl->getResultType(), OpLoc, TheCall.get(), 
+                                FnDecl))
+          return ExprError();
       } else {
         // We matched a built-in operator. Convert the arguments, then
         // break out so that we will build the appropriate built-in
index e44a6989c7b49dc487ca3faa8bdd215aea6e63ef..7b79fa5f4af9605e1851d8bab30772f48393d881 100644 (file)
@@ -5050,6 +5050,10 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
                                                     ResultTy, RParenLoc));
   delete [] MethodArgs;
 
+  if (CheckCallReturnType(Method->getResultType(), LParenLoc, TheCall.get(), 
+                          Method))
+    return true;
+  
   // We may have default arguments. If so, we need to allocate more
   // slots in the call for them.
   if (NumArgs < NumArgsInProto)
index 305c437169f032fc2ebe7027d423aa809d0b1fea..cdb81f393415cd38f5938a712ec97c4a84dac7ea 100644 (file)
@@ -1,13 +1,14 @@
 // RUN: clang-cc -fsyntax-only -verify %s
-struct A; // expected-note 8 {{forward declaration of 'struct A'}}
+struct A; // expected-note 10 {{forward declaration of 'struct A'}}
 
 A f(); // expected-note {{note: 'f' declared here}}
 
 struct B {
   A f(); // expected-note {{'f' declared here}}
-  A operator()(); // expected-note {{'operator()' declared here}}
+  A operator()(); // expected-note {{'operator()' declared here}}
   operator A(); // expected-note {{'operator A' declared here}}
   A operator!(); // expected-note 2 {{'operator!' declared here}}
+  A operator++(int); // expected-note {{'operator++' declared here}}
 };
 
 void g() {
@@ -26,4 +27,6 @@ void g() {
   b.operator!(); // expected-error {{calling 'operator!' with incomplete return type 'struct A'}}
   
   !b; // expected-error {{calling 'operator!' with incomplete return type 'struct A'}}
+  b(); // expected-error {{calling 'operator()' with incomplete return type 'struct A'}}
+  b++; // expected-error {{calling 'operator++' with incomplete return type 'struct A'}}
 }