diff options
| author | Francois Pichet <pichet2000@gmail.com> | 2011-11-17 03:44:24 +0000 |
|---|---|---|
| committer | Francois Pichet <pichet2000@gmail.com> | 2011-11-17 03:44:24 +0000 |
| commit | 857f9d6e5eef4efe9a9df1fd22f20210eeac5fc6 (patch) | |
| tree | 8fda448d28a28f4e21365236236a98c3a1b71d73 /clang/lib | |
| parent | 5acdf59ebc6839fc877604168eb96a76fdb51e77 (diff) | |
| download | bcm5719-llvm-857f9d6e5eef4efe9a9df1fd22f20210eeac5fc6.tar.gz bcm5719-llvm-857f9d6e5eef4efe9a9df1fd22f20210eeac5fc6.zip | |
In Microsoft mode, make "Unqualified lookup into dependent bases of class templates" works inside default argument instantiation.
This is a little bit tricky because during default argument instantiation the CurContext points to a CXXMethodDecl but we can't use the keyword this or have an implicit member call generated.
This fixes 2 errors when parsing MFC code with clang.
llvm-svn: 144881
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 18 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaOverload.cpp | 2 |
2 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 362aea9a74f..ba9dbedd8df 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1520,10 +1520,17 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, // Don't give errors about ambiguities in this lookup. R.suppressDiagnostics(); + // During a default argument instantiation the CurContext points + // to a CXXMethodDecl; but we can't apply a this-> fixit inside a + // function parameter list, hence add an explicit check. + bool isDefaultArgument = !ActiveTemplateInstantiations.empty() && + ActiveTemplateInstantiations.back().Kind == + ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation; CXXMethodDecl *CurMethod = dyn_cast<CXXMethodDecl>(CurContext); bool isInstance = CurMethod && CurMethod->isInstance() && - DC == CurMethod->getParent(); + DC == CurMethod->getParent() && !isDefaultArgument; + // Give a code modification hint to insert 'this->'. // TODO: fixit for inserting 'Base<T>::' in the other cases. @@ -1569,6 +1576,15 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) Diag((*I)->getLocation(), diag::note_dependent_var_use); + // Return true if we are inside a default argument instantiation + // and the found name refers to an instance member function, otherwise + // the function calling DiagnoseEmptyLookup will try to create an + // implicit member call and this is wrong for default argument. + if (isDefaultArgument && ((*R.begin())->isCXXInstanceMember())) { + Diag(R.getNameLoc(), diag::err_member_call_without_object); + return true; + } + // Tell the callee to try to recover. return false; } diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index adf4dcae1b0..24381a30d79 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -8712,7 +8712,7 @@ Sema::BuildOverloadedCallExpr(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, // to instantiation time to be able to search into type dependent base // classes. if (getLangOptions().MicrosoftMode && CurContext->isDependentContext() && - isa<CXXMethodDecl>(CurContext)) { + (isa<CXXMethodDecl>(CurContext) || isa<CXXRecordDecl>(CurContext))) { CallExpr *CE = new (Context) CallExpr(Context, Fn, Args, NumArgs, Context.DependentTy, VK_RValue, RParenLoc); |

