summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2015-09-30 17:30:48 +0000
committerReid Kleckner <rnk@google.com>2015-09-30 17:30:48 +0000
commit21525e7fd4f45b6cfd6d68dbbf10e2cb8d7ebbf0 (patch)
tree877edf3ae80f342e1875fe9e77aee6ad92707e83 /clang/lib/Sema/SemaExpr.cpp
parent4c457758805e5090a842509e19860b08e024ed07 (diff)
downloadbcm5719-llvm-21525e7fd4f45b6cfd6d68dbbf10e2cb8d7ebbf0.tar.gz
bcm5719-llvm-21525e7fd4f45b6cfd6d68dbbf10e2cb8d7ebbf0.zip
[Sema] Avoid crashing during this-> insertion recovery
We get into this bad state when someone defines a new member function for a class but forgets to add the declaration to the class body. Calling the new member function from a member function template of the class will crash during instantiation. llvm-svn: 248925
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8e4624304e0..be0da09f265 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1824,7 +1824,6 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
bool isInstance = CurMethod &&
CurMethod->isInstance() &&
DC == CurMethod->getParent() && !isDefaultArgument;
-
// Give a code modification hint to insert 'this->'.
// TODO: fixit for inserting 'Base<T>::' in the other cases.
@@ -1838,15 +1837,23 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
CallsUndergoingInstantiation.back()->getCallee());
CXXMethodDecl *DepMethod;
- if (CurMethod->isDependentContext())
+ if (CurMethod->isDependentContext()) {
DepMethod = CurMethod;
- else if (CurMethod->getTemplatedKind() ==
- FunctionDecl::TK_FunctionTemplateSpecialization)
- DepMethod = cast<CXXMethodDecl>(CurMethod->getPrimaryTemplate()->
- getInstantiatedFromMemberTemplate()->getTemplatedDecl());
- else
+ } else if (FunctionTemplateDecl *FTD =
+ CurMethod->getPrimaryTemplate()) {
+ // We have a member function template. It may be contained in a
+ // class template. If so, get the original pattern for the member
+ // function template. Otherwise, 'this' isn't dependent and we can
+ // use CurMethod as is.
+ if (FunctionTemplateDecl *MemberFTD =
+ FTD->getInstantiatedFromMemberTemplate())
+ DepMethod = cast<CXXMethodDecl>(MemberFTD->getTemplatedDecl());
+ else
+ DepMethod = CurMethod;
+ } else {
DepMethod = cast<CXXMethodDecl>(
CurMethod->getInstantiatedFromMemberFunction());
+ }
assert(DepMethod && "No template pattern found");
QualType DepThisType = DepMethod->getThisType(Context);
@@ -1856,7 +1863,7 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
TemplateArgumentListInfo TList;
if (ULE->hasExplicitTemplateArgs())
ULE->copyTemplateArgumentsInto(TList);
-
+
CXXScopeSpec SS;
SS.Adopt(ULE->getQualifierLoc());
CXXDependentScopeMemberExpr *DepExpr =
OpenPOWER on IntegriCloud