]> granicus.if.org Git - clang/commitdiff
Diagnose invalid return types for unary operators.
authorAnders Carlsson <andersca@mac.com>
Tue, 13 Oct 2009 21:19:37 +0000 (21:19 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 13 Oct 2009 21:19:37 +0000 (21:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84030 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7744ae7c59d1b9e5741c882c92c147a280fc923a..e44a6989c7b49dc487ca3faa8bdd215aea6e63ef 100644 (file)
@@ -4526,9 +4526,7 @@ Sema::OwningExprResult Sema::CreateOverloadedUnaryOp(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(),
@@ -4537,9 +4535,15 @@ Sema::OwningExprResult Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc,
 
       input.release();
 
-      Expr *CE = new (Context) CXXOperatorCallExpr(Context, Op, FnExpr,
-                                                   &Input, 1, ResultTy, OpLoc);
-      return MaybeBindToTemporary(CE);
+      ExprOwningPtr<CallExpr> TheCall(this,
+        new (Context) CXXOperatorCallExpr(Context, Op, FnExpr,
+                                          &Input, 1, 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
index a9f49d206a1e71da137b01525a7f350a2cef7b54..305c437169f032fc2ebe7027d423aa809d0b1fea 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: clang-cc -fsyntax-only -verify %s
-struct A; // expected-note 6 {{forward declaration of 'struct A'}}
+struct A; // expected-note 8 {{forward declaration of 'struct A'}}
 
 A f(); // expected-note {{note: 'f' declared here}}
 
@@ -7,6 +7,7 @@ struct B {
   A f(); // expected-note {{'f' 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}}
 };
 
 void g() {
@@ -22,4 +23,7 @@ void g() {
   
   b.operator()(); // expected-error {{calling 'operator()' with incomplete return type 'struct A'}}
   b.operator A(); // expected-error {{calling 'operator A' with incomplete return type 'struct A'}}
+  b.operator!(); // expected-error {{calling 'operator!' with incomplete return type 'struct A'}}
+  
+  !b; // expected-error {{calling 'operator!' with incomplete return type 'struct A'}}
 }