From: Anders Carlsson Date: Tue, 13 Oct 2009 21:19:37 +0000 (+0000) Subject: Diagnose invalid return types for unary operators. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=26a2a07acfacc06406e6a48c6d22e4b26bcd6382;p=clang Diagnose invalid return types for unary operators. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84030 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 7744ae7c59..e44a6989c7 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -4526,9 +4526,7 @@ Sema::OwningExprResult Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, } // Determine the result type - QualType ResultTy - = FnDecl->getType()->getAs()->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 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 diff --git a/test/SemaCXX/incomplete-call.cpp b/test/SemaCXX/incomplete-call.cpp index a9f49d206a..305c437169 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 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'}} }