[cfe-commits] r153445 - in /cfe/trunk: include/clang/Sema/TypoCorrection.h lib/Sema/SemaDecl.cpp lib/Sema/SemaLookup.cpp test/FixIt/typo-crash.cpp

Kaelyn Uhrain rikka at google.com
Tue Mar 27 12:58:58 PDT 2012


Doug,

This band-aid looks good to me, though adding another special flag to the
correction callback object somehow seems... dirty. I've added tackling the
FIXMEs for actually performing the correction to my queue of "things to
address once I'm working on clang itself again". ;)

Thanks for taking care of the crasher for me!

Cheers,
Kaelyn

On Mon, Mar 26, 2012 at 9:54 AM, Douglas Gregor <dgregor at apple.com> wrote:

> Author: dgregor
> Date: Mon Mar 26 11:54:18 2012
> New Revision: 153445
>
> URL: http://llvm.org/viewvc/llvm-project?rev=153445&view=rev
> Log:
> 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 / <rdar://problem/11075219>.
>
> Modified:
>    cfe/trunk/include/clang/Sema/TypoCorrection.h
>    cfe/trunk/lib/Sema/SemaDecl.cpp
>    cfe/trunk/lib/Sema/SemaLookup.cpp
>    cfe/trunk/test/FixIt/typo-crash.cpp
>
> Modified: cfe/trunk/include/clang/Sema/TypoCorrection.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/TypoCorrection.h?rev=153445&r1=153444&r2=153445&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/TypoCorrection.h (original)
> +++ cfe/trunk/include/clang/Sema/TypoCorrection.h Mon Mar 26 11:54:18 2012
> @@ -205,7 +205,7 @@
>       : WantTypeSpecifiers(true), WantExpressionKeywords(true),
>         WantCXXNamedCasts(true), WantRemainingKeywords(true),
>         WantObjCSuper(false),
> -        IsObjCIvarLookup(false) {}
> +        IsObjCIvarLookup(false), AllowAddedQualifier(true) {}
>
>   virtual ~CorrectionCandidateCallback() {}
>
> @@ -239,6 +239,10 @@
>   // Temporary hack for the one case where a CorrectTypoContext enum is
> used
>   // when looking up results.
>   bool IsObjCIvarLookup;
> +
> +  /// \brief Whether to allow this typo correction to add a
> +  /// nested-name-specifier.
> +  bool AllowAddedQualifier;
>  };
>
>  /// @brief Simple template class for restricting typo correction
> candidates
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=153445&r1=153444&r2=153445&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Mar 26 11:54:18 2012
> @@ -4478,7 +4478,14 @@
>  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)
>
> Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=153445&r1=153444&r2=153445&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Mar 26 11:54:18 2012
> @@ -3806,7 +3806,13 @@
>     }
>   }
>
> -  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 @@
>     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<NamespaceDecl *, 4> ExternalKnownNamespaces;
> @@ -3948,7 +3955,7 @@
>       break;
>
>     // Only perform the qualified lookups for C++
> -    if (getLangOpts().CPlusPlus) {
> +    if (SearchNamespaces) {
>       TmpRes.suppressDiagnostics();
>       for (llvm::SmallVector<TypoCorrection,
>                              16>::iterator QRI = QualifiedResults.begin(),
>
> Modified: cfe/trunk/test/FixIt/typo-crash.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo-crash.cpp?rev=153445&r1=153444&r2=153445&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/FixIt/typo-crash.cpp (original)
> +++ cfe/trunk/test/FixIt/typo-crash.cpp Mon Mar 26 11:54:18 2012
> @@ -10,3 +10,20 @@
>   // expected-error {{reference to overloaded function could not be
> resolved; did you mean to call it?}} \
>   // expected-error {{use of undeclared identifier 't'}}
>  }
> +
> +// FIXME: It would be nice if we could get this correction right.
> +namespace PR12297 {
> +  namespace A {
> +    typedef short   T;
> +
> +    namespace B {
> +      typedef short   T;
> +
> +      T global();
> +    }
> +  }
> +
> +  using namespace A::B;
> +
> +  T A::global(); // expected-error{{out-of-line definition of 'global'
> does not match any declaration in namespace 'PR12297::A'}}
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120327/b57767b9/attachment.html>


More information about the cfe-commits mailing list