Check the return type of operator[]() and fix a thinko that lead to a crash in SemaCXX/overloaded-operator.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84041 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 56dd670..d8e49c7 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1590,6 +1590,8 @@
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 @@
}
// 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 @@
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
diff --git a/test/SemaCXX/incomplete-call.cpp b/test/SemaCXX/incomplete-call.cpp
index cdb81f3..4decd86 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 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 @@
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 @@
!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'}}
}