diff options
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/AnalysisBasedWarnings.cpp | 48 | ||||
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 32 | ||||
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 25 |
3 files changed, 33 insertions, 72 deletions
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index e6f2f82dd27..967f521b202 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -1089,24 +1089,6 @@ static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC, } -namespace { -typedef std::pair<const Stmt *, - sema::FunctionScopeInfo::WeakObjectUseMap::const_iterator> - StmtUsesPair; - -class StmtUseSorter { - const SourceManager &SM; - -public: - explicit StmtUseSorter(const SourceManager &SM) : SM(SM) { } - - bool operator()(const StmtUsesPair &LHS, const StmtUsesPair &RHS) { - return SM.isBeforeInTranslationUnit(LHS.first->getLocStart(), - RHS.first->getLocStart()); - } -}; -} - static bool isInLoop(const ASTContext &Ctx, const ParentMap &PM, const Stmt *S) { assert(S); @@ -1141,6 +1123,8 @@ static void diagnoseRepeatedUseOfWeak(Sema &S, typedef sema::FunctionScopeInfo::WeakObjectProfileTy WeakObjectProfileTy; typedef sema::FunctionScopeInfo::WeakObjectUseMap WeakObjectUseMap; typedef sema::FunctionScopeInfo::WeakUseVector WeakUseVector; + typedef std::pair<const Stmt *, WeakObjectUseMap::const_iterator> + StmtUsesPair; ASTContext &Ctx = S.getASTContext(); @@ -1199,8 +1183,12 @@ static void diagnoseRepeatedUseOfWeak(Sema &S, return; // Sort by first use so that we emit the warnings in a deterministic order. + SourceManager &SM = S.getSourceManager(); std::sort(UsesByStmt.begin(), UsesByStmt.end(), - StmtUseSorter(S.getSourceManager())); + [&SM](const StmtUsesPair &LHS, const StmtUsesPair &RHS) { + return SM.isBeforeInTranslationUnit(LHS.first->getLocStart(), + RHS.first->getLocStart()); + }); // Classify the current code body for better warning text. // This enum should stay in sync with the cases in @@ -1281,19 +1269,7 @@ static void diagnoseRepeatedUseOfWeak(Sema &S, } } - namespace { -struct SLocSort { - bool operator()(const UninitUse &a, const UninitUse &b) { - // Prefer a more confident report over a less confident one. - if (a.getKind() != b.getKind()) - return a.getKind() > b.getKind(); - SourceLocation aLoc = a.getUser()->getLocStart(); - SourceLocation bLoc = b.getUser()->getLocStart(); - return aLoc.getRawEncoding() < bLoc.getRawEncoding(); - } -}; - class UninitValsDiagReporter : public UninitVariablesHandler { Sema &S; typedef SmallVector<UninitUse, 2> UsesVec; @@ -1352,8 +1328,14 @@ public: // Sort the uses by their SourceLocations. While not strictly // guaranteed to produce them in line/column order, this will provide // a stable ordering. - std::sort(vec->begin(), vec->end(), SLocSort()); - + std::sort(vec->begin(), vec->end(), + [](const UninitUse &a, const UninitUse &b) { + // Prefer a more confident report over a less confident one. + if (a.getKind() != b.getKind()) + return a.getKind() > b.getKind(); + return a.getUser()->getLocStart() < b.getUser()->getLocStart(); + }); + for (UsesVec::iterator vi = vec->begin(), ve = vec->end(); vi != ve; ++vi) { // If we have self-init, downgrade all uses to 'may be uninitialized'. diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 037327a22da..aa223bacaba 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -409,25 +409,6 @@ static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) { return false; } -namespace { - struct SortUndefinedButUsed { - const SourceManager &SM; - explicit SortUndefinedButUsed(SourceManager &SM) : SM(SM) {} - - bool operator()(const std::pair<NamedDecl *, SourceLocation> &l, - const std::pair<NamedDecl *, SourceLocation> &r) const { - if (l.second.isValid() && !r.second.isValid()) - return true; - if (!l.second.isValid() && r.second.isValid()) - return false; - if (l.second != r.second) - return SM.isBeforeInTranslationUnit(l.second, r.second); - return SM.isBeforeInTranslationUnit(l.first->getLocation(), - r.first->getLocation()); - } - }; -} - /// Obtains a sorted list of functions that are undefined but ODR-used. void Sema::getUndefinedButUsed( SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined) { @@ -460,8 +441,19 @@ void Sema::getUndefinedButUsed( // Sort (in order of use site) so that we're not dependent on the iteration // order through an llvm::DenseMap. + SourceManager &SM = Context.getSourceManager(); std::sort(Undefined.begin(), Undefined.end(), - SortUndefinedButUsed(Context.getSourceManager())); + [&SM](const std::pair<NamedDecl *, SourceLocation> &l, + const std::pair<NamedDecl *, SourceLocation> &r) { + if (l.second.isValid() && !r.second.isValid()) + return true; + if (!l.second.isValid() && r.second.isValid()) + return false; + if (l.second != r.second) + return SM.isBeforeInTranslationUnit(l.second, r.second); + return SM.isBeforeInTranslationUnit(l.first->getLocation(), + r.first->getLocation()); + }); } /// checkUndefinedButUsed - Check for undefined objects with internal linkage diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 5369a4beb21..28f85d7a9f1 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -3825,22 +3825,6 @@ void Sema::CodeCompleteCase(Scope *S) { Results.data(),Results.size()); } -namespace { - struct IsBetterOverloadCandidate { - Sema &S; - SourceLocation Loc; - - public: - explicit IsBetterOverloadCandidate(Sema &S, SourceLocation Loc) - : S(S), Loc(Loc) { } - - bool - operator()(const OverloadCandidate &X, const OverloadCandidate &Y) const { - return isBetterOverloadCandidate(S, X, Y, Loc); - } - }; -} - static bool anyNullArguments(ArrayRef<Expr *> Args) { if (Args.size() && !Args.data()) return true; @@ -3902,9 +3886,12 @@ void Sema::CodeCompleteCall(Scope *S, Expr *FnIn, ArrayRef<Expr *> Args) { if (!CandidateSet.empty()) { // Sort the overload candidate set by placing the best overloads first. - std::stable_sort(CandidateSet.begin(), CandidateSet.end(), - IsBetterOverloadCandidate(*this, Loc)); - + std::stable_sort( + CandidateSet.begin(), CandidateSet.end(), + [&](const OverloadCandidate &X, const OverloadCandidate &Y) { + return isBetterOverloadCandidate(*this, X, Y, Loc); + }); + // Add the remaining viable overload candidates as code-completion reslults. for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(), CandEnd = CandidateSet.end(); |