[cfe-commits] [cfe-dev] Make namespace typo correction always deterministic

Nick Lewycky nlewycky at google.com
Tue Jun 28 15:31:36 PDT 2011


On 28 June 2011 15:11, Kaelyn Uhrain <rikka at google.com> wrote:

> Without this patch, if there are two different but valid namespace
> qualifiers for reaching the same decl, which one was used was determined by
> the (undefined) order the namespaces were checked for the identifer. This
> patch adds a simple heuristic that keeps whichever version would come first
> lexicographically.
>

+  TypoResultsMap::iterator elt = Map->find(Name);
+  if (elt == Map->end() || Correction.getAsString(SemaRef.getLangOptions())
<
+      elt->second.getAsString(SemaRef.getLangOptions()))
+    (*Map)[Name] = Correction;

This effectively does Map->find(name) twice, once to get elt and once to set
it to Correction (the operator[] will run it again).

Would this work?

  TypoCorrection &BestCorrection = (*Map)[Name];
  if (!BestCorrection || Correction.getAsString(SemaRef.getLangOptions()) <
BestCorrection.getAsString(SemaRef.getLangOptions()))
    BestCorrection = Correction;

It might not if there's no copy/assignment on TypoCorrection.

Nick


>
> Cheers,
> Kaelyn
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110628/b03fb20c/attachment.html>


More information about the cfe-commits mailing list