forked from OSchip/llvm-project
Check the return type of operator[]() and fix a thinko that lead to a crash in SemaCXX/overloaded-operator.cpp.
llvm-svn: 84041
This commit is contained in:
parent
f50799412c
commit
834facc2b0
|
@ -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<FunctionType>()->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<CXXOperatorCallExpr>
|
||||
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
|
||||
|
|
|
@ -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'}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue