diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-06-08 21:35:42 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-06-08 21:35:42 +0000 |
commit | 0f4b5be4a3b3e1c18e611e5a5c262ef028e8320a (patch) | |
tree | ef186b4c99adb27a73713c735186e970eefcab7d | |
parent | 9f63a451b1b3e36c0c82fcfe78828182bb9a6fa0 (diff) |
PR13051: Only suggest the 'template' and 'operator' keywords when performing
typo-correction after a scope specifier.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158231 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 13 | ||||
-rw-r--r-- | test/SemaCXX/typo-correction.cpp | 13 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 91d76de172..ded441cac6 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -3533,7 +3533,16 @@ static void LookupPotentialTypoResult(Sema &SemaRef, /// \brief Add keywords to the consumer as possible typo corrections. static void AddKeywordsToConsumer(Sema &SemaRef, TypoCorrectionConsumer &Consumer, - Scope *S, CorrectionCandidateCallback &CCC) { + Scope *S, CorrectionCandidateCallback &CCC, + bool AfterNestedNameSpecifier) { + if (AfterNestedNameSpecifier) { + // For 'X::', we know exactly which keywords can appear next. + Consumer.addKeywordResult("template"); + if (CCC.WantExpressionKeywords) + Consumer.addKeywordResult("operator"); + return; + } + if (CCC.WantObjCSuper) Consumer.addKeywordResult("super"); @@ -3823,7 +3832,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, } } - AddKeywordsToConsumer(*this, Consumer, S, CCC); + AddKeywordsToConsumer(*this, Consumer, S, CCC, SS && SS->isNotEmpty()); // If we haven't found anything, we're done. if (Consumer.empty()) { diff --git a/test/SemaCXX/typo-correction.cpp b/test/SemaCXX/typo-correction.cpp index fb07ce127e..90fdb221f9 100644 --- a/test/SemaCXX/typo-correction.cpp +++ b/test/SemaCXX/typo-correction.cpp @@ -206,3 +206,16 @@ namespace foobar { struct Thing {}; } namespace bazquux { struct Thing {}; } void f() { Thing t; } // expected-error{{unknown type name 'Thing'}} } + +namespace PR13051 { + template<typename T> struct S { + template<typename U> void f(); + operator bool() const; + }; + + void f() { + f(&S<int>::tempalte f<int>); // expected-error{{did you mean 'template'?}} + f(&S<int>::opeartor bool); // expected-error{{did you mean 'operator'?}} + f(&S<int>::foo); // expected-error-re{{no member named 'foo' in 'PR13051::S<int>'$}} + } +} |