Allow CorrectTypo to replace CXXScopeSpecifiers that refer to classes.

Now that CorrectTypo knows how to correctly search classes for typo
correction candidates, there is no good reason to only replace an
existing CXXScopeSpecifier if it refers to a namespace. While the actual
enablement was a matter of changing a single comparison, the fallout
from enabling the functionality required a lot more code changes
(including my two previous commits).

llvm-svn: 193020
This commit is contained in:
Kaelyn Uhrain
2013-10-19 00:05:00 +00:00
parent f7b63e3e18
commit 8aa8da85ca
12 changed files with 113 additions and 44 deletions

View File

@@ -4157,7 +4157,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
// corrections.
bool SearchNamespaces
= getLangOpts().CPlusPlus &&
(IsUnqualifiedLookup || (QualifiedDC && QualifiedDC->isNamespace()));
(IsUnqualifiedLookup || (SS && SS->isSet()));
// In a few cases we *only* want to search for corrections based on just
// adding or changing the nested name specifier.
unsigned TypoLen = Typo->getName().size();
@@ -4400,6 +4400,18 @@ retry_lookup:
switch (TmpRes.getResultKind()) {
case LookupResult::Found:
case LookupResult::FoundOverloaded: {
if (SS && SS->isValid()) {
std::string NewQualified = TC.getAsString(getLangOpts());
std::string OldQualified;
llvm::raw_string_ostream OldOStream(OldQualified);
SS->getScopeRep()->print(OldOStream, getPrintingPolicy());
OldOStream << TypoName;
// If correction candidate would be an identical written qualified
// identifer, then the existing CXXScopeSpec probably included a
// typedef that didn't get accounted for properly.
if (OldOStream.str() == NewQualified)
break;
}
for (LookupResult::iterator TRD = TmpRes.begin(),
TRDEnd = TmpRes.end();
TRD != TRDEnd; ++TRD) {