<div class="gmail_quote">On Thu, Jun 7, 2012 at 5:15 PM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com" target="_blank">dgregor@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
On Jun 7, 2012, at 4:57 PM, Kaelyn Uhrain wrote:<br>
<br>
> Author: rikka<br>
> Date: Thu Jun  7 18:57:12 2012<br>
> New Revision: 158178<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=158178&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=158178&view=rev</a><br>
> Log:<br>
> Teach the FixIt in DiagnoseInvalidRedeclaration how to replace the written<br>
> nested name specifiers in addition to the function's identifier when the<br>
> correction has a different nested name specifier.<br>
><br>
> Modified:<br>
>    cfe/trunk/lib/Sema/SemaDecl.cpp<br>
>    cfe/trunk/test/FixIt/fixit.cpp<br>
><br>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=158178&r1=158177&r2=158178&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=158178&r1=158177&r2=158178&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jun  7 18:57:12 2012<br>
> @@ -4742,15 +4742,19 @@<br>
>     }<br>
>   }<br>
><br>
> -  if (Correction)<br>
> -    SemaRef.Diag(NewFD->getLocation(), DiagMsg)<br>
> +  if (Correction) {<br>
> +    SourceRange FixItLoc(NewFD->getLocation());<br>
> +    CXXScopeSpec &SS = ExtraArgs.D.getCXXScopeSpec();<br>
> +    if (Correction.getCorrectionSpecifier() && SS.isValid())<br>
> +      FixItLoc.setBegin(SS.getBeginLoc());<br>
> +    SemaRef.Diag(NewFD->getLocStart(), DiagMsg)<br>
>         << Name << NewDC << Correction.getQuoted(SemaRef.getLangOpts())<br>
>         << FixItHint::CreateReplacement(<br>
> -            NewFD->getLocation(),<br>
> -            Correction.getAsString(SemaRef.getLangOpts()));<br>
> -  else<br>
> +            FixItLoc, Correction.getAsString(SemaRef.getLangOpts()));<br>
<br>
</div></div>Don't you also need to update D.getCXXScopeSpec() to the correction specifier?<br></blockquote><div><br></div><div>If I remember correctly from way back when I first added the namespace-aware typo correction support, changing that CXXScopeSpec broke things in unexpected ways.... though it may also have been that I did not (and still don't) know how update it with the freshly synthesized NestedNameSpecifier* that lacks location information--or even that things broke because I hadn't created a corresponding NestedNameSpecifierLoc with valid location info. Though from what I can tell e.g. with the test case I added to make sure the substitution didn't leave the old specifier in the code, updating D.getCXXScopeSpecifier() isn't necessary.</div>
<div><br></div><div>Cheers,</div><div>Kaelyn</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
        - Doug<br>
<div class="HOEnZb"><div class="h5"><br>
> +  } else {<br>
>     SemaRef.Diag(NewFD->getLocation(), DiagMsg)<br>
>         << Name << NewDC << NewFD->getLocation();<br>
> +  }<br>
><br>
>   bool NewFDisConst = false;<br>
>   if (CXXMethodDecl *NewMD = dyn_cast<CXXMethodDecl>(NewFD))<br>
><br>
> Modified: cfe/trunk/test/FixIt/fixit.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=158178&r1=158177&r2=158178&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=158178&r1=158177&r2=158178&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/test/FixIt/fixit.cpp (original)<br>
> +++ cfe/trunk/test/FixIt/fixit.cpp Thu Jun  7 18:57:12 2012<br>
> @@ -242,3 +242,21 @@<br>
> }<br>
><br>
> } // namespace arrow_suggest<br>
> +<br>
> +// Make sure fixing namespace-qualified identifiers functions properly with<br>
> +// namespace-aware typo correction/<br>
> +namespace redecl_typo {<br>
> +namespace Foo {<br>
> +  void BeEvil(); // expected-note {{'BeEvil' declared here}}<br>
> +}<br>
> +namespace Bar {<br>
> +  namespace Foo {<br>
> +    bool isGood(); // expected-note {{'Bar::Foo::isGood' declared here}}<br>
> +    void beEvil();<br>
> +  }<br>
> +}<br>
> +bool Foo::isGood() { // expected-error {{out-of-line definition of 'isGood' does not match any declaration in namespace 'redecl_typo::Foo'; did you mean 'Bar::Foo::isGood'?}}<br>
> +  return true;<br>
> +}<br>
> +void Foo::beEvil() {} // expected-error {{out-of-line definition of 'beEvil' does not match any declaration in namespace 'redecl_typo::Foo'; did you mean 'BeEvil'?}}<br>
> +}<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br>
</div></div></blockquote></div><br>