diff options
author | Kaelyn Uhrain <rikka@google.com> | 2012-06-07 23:57:12 +0000 |
---|---|---|
committer | Kaelyn Uhrain <rikka@google.com> | 2012-06-07 23:57:12 +0000 |
commit | 1dac08da4b141848d9ee7b4b331dfb625f7d045a (patch) | |
tree | 31ef691194c3fd919629b3b7e1e5df8893634215 | |
parent | 389e9c2d7cfd12156825b1cdd5b4549b48987bc6 (diff) | |
download | bcm5719-llvm-1dac08da4b141848d9ee7b4b331dfb625f7d045a.tar.gz bcm5719-llvm-1dac08da4b141848d9ee7b4b331dfb625f7d045a.zip |
Teach the FixIt in DiagnoseInvalidRedeclaration how to replace the written
nested name specifiers in addition to the function's identifier when the
correction has a different nested name specifier.
llvm-svn: 158178
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 14 | ||||
-rw-r--r-- | clang/test/FixIt/fixit.cpp | 18 |
2 files changed, 27 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 44a2bb5d5ae..fdda9014dc1 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -4742,15 +4742,19 @@ static NamedDecl* DiagnoseInvalidRedeclaration( } } - if (Correction) - SemaRef.Diag(NewFD->getLocation(), DiagMsg) + if (Correction) { + SourceRange FixItLoc(NewFD->getLocation()); + CXXScopeSpec &SS = ExtraArgs.D.getCXXScopeSpec(); + if (Correction.getCorrectionSpecifier() && SS.isValid()) + FixItLoc.setBegin(SS.getBeginLoc()); + SemaRef.Diag(NewFD->getLocStart(), DiagMsg) << Name << NewDC << Correction.getQuoted(SemaRef.getLangOpts()) << FixItHint::CreateReplacement( - NewFD->getLocation(), - Correction.getAsString(SemaRef.getLangOpts())); - else + FixItLoc, Correction.getAsString(SemaRef.getLangOpts())); + } else { SemaRef.Diag(NewFD->getLocation(), DiagMsg) << Name << NewDC << NewFD->getLocation(); + } bool NewFDisConst = false; if (CXXMethodDecl *NewMD = dyn_cast<CXXMethodDecl>(NewFD)) diff --git a/clang/test/FixIt/fixit.cpp b/clang/test/FixIt/fixit.cpp index 86a2dd44754..f5338cf01b8 100644 --- a/clang/test/FixIt/fixit.cpp +++ b/clang/test/FixIt/fixit.cpp @@ -242,3 +242,21 @@ void test() { } } // namespace arrow_suggest + +// Make sure fixing namespace-qualified identifiers functions properly with +// namespace-aware typo correction/ +namespace redecl_typo { +namespace Foo { + void BeEvil(); // expected-note {{'BeEvil' declared here}} +} +namespace Bar { + namespace Foo { + bool isGood(); // expected-note {{'Bar::Foo::isGood' declared here}} + void beEvil(); + } +} +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'?}} + return true; +} +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'?}} +} |