From 7c2cb864c424f895bcea19c59d915eb07640ec03 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 14 May 2016 01:58:49 +0000 Subject: [PATCH] When typo-correcting a using-declaration, actually correct the name of the UsingDecl (so that redeclaration lookup can find it). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@269530 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 4 ++++ test/SemaCXX/using-decl-1.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index ee81bbc287..ca8ed71fce 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -7998,6 +7998,9 @@ public: if (Candidate.WillReplaceSpecifier() && !Candidate.getCorrectionSpecifier()) return false; + // FIXME: Don't correct to a name that CheckUsingDeclRedeclaration would + // reject. + if (RequireMemberOf) { auto *FoundRecord = dyn_cast(ND); if (FoundRecord && FoundRecord->isInjectedClassName()) { @@ -8207,6 +8210,7 @@ NamedDecl *Sema::BuildUsingDeclaration(Scope *S, AccessSpecifier AS, R.addDecl(Ctor); } else { // FIXME: Pick up all the declarations if we found an overloaded function. + NameInfo.setName(ND->getDeclName()); R.addDecl(ND); } } else { diff --git a/test/SemaCXX/using-decl-1.cpp b/test/SemaCXX/using-decl-1.cpp index e17612d277..93f38f28e7 100644 --- a/test/SemaCXX/using-decl-1.cpp +++ b/test/SemaCXX/using-decl-1.cpp @@ -243,6 +243,41 @@ namespace PR19171 { struct F : E { using E::EE; // expected-error-re {{no member named 'EE' in 'PR19171::E'{{$}}}} }; + + struct TypoDuplicate { // expected-note 0-4{{here}} + TypoDuplicate(int); + void foobar(); // expected-note 2{{here}} + }; + struct TypoDuplicateDerived1 : TypoDuplicate { +#if __cplusplus >= 201103L + using TypoDuplicate::TypoFuplicate; // expected-error {{did you mean 'TypoDuplicate'}} expected-note {{previous}} + using TypoDuplicate::TypoDuplicate; // expected-error {{redeclaration}} +#endif + using TypoDuplicate::goobar; // expected-error {{did you mean 'foobar'}} expected-note {{previous}} + using TypoDuplicate::foobar; // expected-error {{redeclaration}} + }; + struct TypoDuplicateDerived2 : TypoDuplicate { +#if __cplusplus >= 201103L + using TypoFuplicate::TypoDuplicate; // expected-error {{did you mean 'TypoDuplicate'}} expected-note {{previous}} + using TypoDuplicate::TypoDuplicate; // expected-error {{redeclaration}} +#endif + }; + struct TypoDuplicateDerived3 : TypoDuplicate { +#if __cplusplus >= 201103L + // FIXME: Don't suggest a correction that would lead to a redeclaration + // error here... or at least diagnose the error. + using TypoDuplicate::TypoDuplicate; + using TypoDuplicate::TypoFuplicate; // expected-error {{did you mean 'TypoDuplicate'}} +#endif + using TypoDuplicate::foobar; + using TypoDuplicate::goobar; // expected-error {{did you mean 'foobar'}} + }; + struct TypoDuplicateDerived4 : TypoDuplicate { +#if __cplusplus >= 201103L + using TypoDuplicate::TypoDuplicate; // expected-note {{previous}} + using TypoFuplicate::TypoDuplicate; // expected-error {{did you mean 'TypoDuplicate'}} expected-error {{redeclaration}} +#endif + }; } namespace TypoCorrectTemplateMember { -- 2.40.0