]> granicus.if.org Git - clang/commitdiff
[Sema] Fix assumption about typo corrections containing no decl.
authorBenjamin Kramer <benny.kra@googlemail.com>
Tue, 24 Jan 2017 12:49:59 +0000 (12:49 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Tue, 24 Jan 2017 12:49:59 +0000 (12:49 +0000)
This can happen when the typo correction is coming from an external sema
source. Test case will follow in clang-tools-extra.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@292927 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp

index f265f4c00f71b93adc0a866a701f59056ac57de3..671d3251a5450dbe8db7ec7377f8cc2d8bcc3c17 100644 (file)
@@ -9169,15 +9169,18 @@ NamedDecl *Sema::BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
                 HasTypenameKeyword, IsInstantiation, SS.getScopeRep(),
                 dyn_cast<CXXRecordDecl>(CurContext)),
             CTK_ErrorRecovery)) {
-      // We reject any correction for which ND would be NULL.
-      NamedDecl *ND = Corrected.getCorrectionDecl();
-
       // We reject candidates where DroppedSpecifier == true, hence the
       // literal '0' below.
       diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
                                 << NameInfo.getName() << LookupContext << 0
                                 << SS.getRange());
 
+      // If we picked a correction with no attached Decl we can't do anything
+      // useful with it, bail out.
+      NamedDecl *ND = Corrected.getCorrectionDecl();
+      if (!ND)
+        return BuildInvalid();
+
       // If we corrected to an inheriting constructor, handle it as one.
       auto *RD = dyn_cast<CXXRecordDecl>(ND);
       if (RD && RD->isInjectedClassName()) {