diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 56dd67023330..d8e49c7d6941 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1590,6 +1590,8 @@ Sema::ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, if (CheckCallReturnType(FnDecl->getResultType(), OpLoc, TheCall.get(), FnDecl)) return ExprError(); + return Owned(TheCall.release()); + } else { // We matched a built-in operator. Convert the arguments, then // break out so that we will build the appropriate built-in @@ -1700,9 +1702,7 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, } // 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(), @@ -1713,9 +1713,16 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, Idx.release(); Args[0] = LHSExp; Args[1] = RHSExp; - return Owned(new (Context) CXXOperatorCallExpr(Context, OO_Subscript, - FnExpr, Args, 2, - ResultTy, LLoc)); + + ExprOwningPtr + TheCall(this, new (Context) CXXOperatorCallExpr(Context, OO_Subscript, + FnExpr, Args, 2, + ResultTy, RLoc)); + if (CheckCallReturnType(FnDecl->getResultType(), LLoc, TheCall.get(), + FnDecl)) + return ExprError(); + + return Owned(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/clang/test/SemaCXX/incomplete-call.cpp b/clang/test/SemaCXX/incomplete-call.cpp index cdb81f393415..4decd864832a 100644 --- a/clang/test/SemaCXX/incomplete-call.cpp +++ b/clang/test/SemaCXX/incomplete-call.cpp @@ -1,5 +1,5 @@ // RUN: clang-cc -fsyntax-only -verify %s -struct A; // expected-note 10 {{forward declaration of 'struct A'}} +struct A; // expected-note 11 {{forward declaration of 'struct A'}} A f(); // expected-note {{note: 'f' declared here}} @@ -9,6 +9,7 @@ struct B { operator A(); // expected-note {{'operator A' declared here}} A operator!(); // expected-note 2 {{'operator!' declared here}} A operator++(int); // expected-note {{'operator++' declared here}} + A operator[](int); // expected-note {{'operator[]' declared here}} }; void g() { @@ -29,4 +30,5 @@ 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++; // expected-error {{calling 'operator++' with incomplete return type 'struct A'}} + b[0]; // expected-error {{calling 'operator[]' with incomplete return type 'struct A'}} }