Index: lib/Sema/SemaOverload.cpp =================================================================== --- lib/Sema/SemaOverload.cpp +++ lib/Sema/SemaOverload.cpp @@ -6371,8 +6371,8 @@ bool FirstArgumentIsBase) { for (UnresolvedSetIterator F = Fns.begin(), E = Fns.end(); F != E; ++F) { NamedDecl *D = F.getDecl()->getUnderlyingDecl(); + ArrayRef FunctionArgs = Args; if (FunctionDecl *FD = dyn_cast(D)) { - ArrayRef FunctionArgs = Args; if (isa(FD) && !cast(FD)->isStatic()) { QualType ObjectType; Expr::Classification ObjectClassification; @@ -6391,8 +6391,9 @@ } else { // Slice the first argument (which is the base) when we access // static method as non-static - if (Args.size() > 0 && (!Args[0] || (FirstArgumentIsBase && isa(FD) && - !isa(FD)))) { + if (Args.size() > 0 && + (!Args[0] || (FirstArgumentIsBase && isa(FD) && + !isa(FD)))) { assert(cast(FD)->isStatic()); FunctionArgs = Args.slice(1); } @@ -6405,22 +6406,33 @@ !cast(FunTmpl->getTemplatedDecl())->isStatic()) { QualType ObjectType; Expr::Classification ObjectClassification; - if (Expr *E = Args[0]) { - // Use the explit base to restrict the lookup: - ObjectType = E->getType(); - ObjectClassification = E->Classify(Context); - } // .. else there is an implit base. + if (Args.size() > 0) { + if (Expr *E = Args[0]) { + // Use the explit base to restrict the lookup: + ObjectType = E->getType(); + ObjectClassification = E->Classify(Context); + } // .. else there is an implit base. + FunctionArgs = Args.slice(1); + } AddMethodTemplateCandidate( FunTmpl, F.getPair(), cast(FunTmpl->getDeclContext()), ExplicitTemplateArgs, ObjectType, ObjectClassification, - Args.slice(1), CandidateSet, SuppressUserConversions, + FunctionArgs, CandidateSet, SuppressUserConversions, PartialOverloading); } else { - AddTemplateOverloadCandidate(FunTmpl, F.getPair(), - ExplicitTemplateArgs, Args, - CandidateSet, SuppressUserConversions, - PartialOverloading); + FunctionDecl *FD = FunTmpl->getTemplatedDecl(); + // Slice the first argument (which is the base) when we access + // static method as non-static + if (Args.size() > 0 && + (!Args[0] || (FirstArgumentIsBase && isa(FD) && + !isa(FD)))) { + assert(cast(FD)->isStatic()); + FunctionArgs = Args.slice(1); + } + AddTemplateOverloadCandidate( + FunTmpl, F.getPair(), ExplicitTemplateArgs, Args, CandidateSet, + SuppressUserConversions, PartialOverloading); } } }