From b11f94590cdaa65a91453e89f1594990b7751449 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 26 Mar 2012 16:54:18 +0000 Subject: When diagnosing an invalid out-of-line redeclaration, don't permit typo correction to introduce a nested-name-specifier; we aren't prepared to handle it here. Fixes PR12297 / . llvm-svn: 153445 --- clang/lib/Sema/SemaDecl.cpp | 9 ++++++++- clang/lib/Sema/SemaLookup.cpp | 15 +++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'clang/lib') diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index e92b3e4acab..d4159bf1895 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -4478,7 +4478,14 @@ namespace { class DifferentNameValidatorCCC : public CorrectionCandidateCallback { public: DifferentNameValidatorCCC(CXXRecordDecl *Parent) - : ExpectedParent(Parent ? Parent->getCanonicalDecl() : 0) {} + : ExpectedParent(Parent ? Parent->getCanonicalDecl() : 0) { + // Don't allow any additional qualification. + // FIXME: It would be nice to perform this additional qualification. + // However, DiagnoseInvalidRedeclaration is unable to handle the + // qualification, because it doesn't know how to pass the corrected + // nested-name-specifier through to ActOnFunctionDeclarator. + AllowAddedQualifier = false; + } virtual bool ValidateCandidate(const TypoCorrection &candidate) { if (candidate.getEditDistance() == 0) diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index e47bc1c8b12..ed5a8da61c3 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -3806,7 +3806,13 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, } } - if (IsUnqualifiedLookup || (QualifiedDC && QualifiedDC->isNamespace())) { + // Determine whether we are going to search in the various namespaces for + // corrections. + bool SearchNamespaces + = getLangOpts().CPlusPlus && CCC.AllowAddedQualifier && + (IsUnqualifiedLookup || (QualifiedDC && QualifiedDC->isNamespace())); + + if (IsUnqualifiedLookup || SearchNamespaces) { // For unqualified lookup, look through all of the names that we have // seen in this translation unit. // FIXME: Re-add the ability to skip very unlikely potential corrections. @@ -3852,8 +3858,9 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, return TypoCorrection(); } - // Build the NestedNameSpecifiers for the KnownNamespaces - if (getLangOpts().CPlusPlus) { + // Build the NestedNameSpecifiers for the KnownNamespaces, if we're going + // to search those namespaces. + if (SearchNamespaces) { // Load any externally-known namespaces. if (ExternalSource && !LoadedExternalKnownNamespaces) { SmallVector ExternalKnownNamespaces; @@ -3948,7 +3955,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, break; // Only perform the qualified lookups for C++ - if (getLangOpts().CPlusPlus) { + if (SearchNamespaces) { TmpRes.suppressDiagnostics(); for (llvm::SmallVector::iterator QRI = QualifiedResults.begin(), -- cgit v1.2.3