[clang] 84ab315 - [clang][NFC] Break out enum completion from other type context completion

Nathan Sidwell via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 7 06:30:16 PDT 2021


Author: Nathan Sidwell
Date: 2021-06-07T06:29:29-07:00
New Revision: 84ab315574099dcac8f9fb89fe8558f8ccfbce5f

URL: https://github.com/llvm/llvm-project/commit/84ab315574099dcac8f9fb89fe8558f8ccfbce5f
DIFF: https://github.com/llvm/llvm-project/commit/84ab315574099dcac8f9fb89fe8558f8ccfbce5f.diff

LOG: [clang][NFC] Break out enum completion from other type context completion

This prepatch for using-enum breaks out the enum completion that that
will need from the existing scope completion logic.

Differential Revision: https://reviews.llvm.org/D102239

Added: 
    

Modified: 
    clang/include/clang/Sema/Sema.h
    clang/lib/Sema/SemaCXXScopeSpec.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 57be1cb6d21c3..4e6d73cbc1aff 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6399,6 +6399,9 @@ class Sema final {
 
   // Marks SS invalid if it represents an incomplete type.
   bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
+  // Complete an enum decl, maybe without a scope spec.
+  bool RequireCompleteEnumDecl(EnumDecl *D, SourceLocation L,
+                               CXXScopeSpec *SS = nullptr);
 
   DeclContext *computeDeclContext(QualType T);
   DeclContext *computeDeclContext(const CXXScopeSpec &SS,

diff  --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp
index a4421d2b68af3..87059eb450858 100644
--- a/clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -227,12 +227,20 @@ bool Sema::RequireCompleteDeclContext(CXXScopeSpec &SS,
     return true;
   }
 
-  // Fixed enum types are complete, but they aren't valid as scopes
-  // until we see a definition, so awkwardly pull out this special
-  // case.
-  auto *EnumD = dyn_cast<EnumDecl>(tag);
-  if (!EnumD)
-    return false;
+  if (auto *EnumD = dyn_cast<EnumDecl>(tag))
+    // Fixed enum types and scoped enum instantiations are complete, but they
+    // aren't valid as scopes until we see or instantiate their definition.
+    return RequireCompleteEnumDecl(EnumD, loc, &SS);
+
+  return false;
+}
+
+/// Require that the EnumDecl is completed with its enumerators defined or
+/// instantiated. SS, if provided, is the ScopeRef parsed.
+///
+bool Sema::RequireCompleteEnumDecl(EnumDecl *EnumD, SourceLocation L,
+                                   CXXScopeSpec *SS) {
+  assert (SS && "missing scope");
   if (EnumD->isCompleteDefinition()) {
     // If we know about the definition but it is not visible, complain.
     NamedDecl *SuggestedDef = nullptr;
@@ -241,8 +249,8 @@ bool Sema::RequireCompleteDeclContext(CXXScopeSpec &SS,
       // If the user is going to see an error here, recover by making the
       // definition visible.
       bool TreatAsComplete = !isSFINAEContext();
-      diagnoseMissingImport(loc, SuggestedDef, MissingImportKind::Definition,
-                            /*Recover*/TreatAsComplete);
+      diagnoseMissingImport(L, SuggestedDef, MissingImportKind::Definition,
+                            /*Recover*/ TreatAsComplete);
       return !TreatAsComplete;
     }
     return false;
@@ -253,19 +261,20 @@ bool Sema::RequireCompleteDeclContext(CXXScopeSpec &SS,
   if (EnumDecl *Pattern = EnumD->getInstantiatedFromMemberEnum()) {
     MemberSpecializationInfo *MSI = EnumD->getMemberSpecializationInfo();
     if (MSI->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) {
-      if (InstantiateEnum(loc, EnumD, Pattern,
+      if (InstantiateEnum(L, EnumD, Pattern,
                           getTemplateInstantiationArgs(EnumD),
                           TSK_ImplicitInstantiation)) {
-        SS.SetInvalid(SS.getRange());
+        SS->SetInvalid(SS->getRange());
         return true;
       }
       return false;
     }
   }
 
-  Diag(loc, diag::err_incomplete_nested_name_spec)
-    << type << SS.getRange();
-  SS.SetInvalid(SS.getRange());
+  Diag(L, diag::err_incomplete_nested_name_spec)
+      << QualType(EnumD->getTypeForDecl(), 0) << SS->getRange();
+  SS->SetInvalid(SS->getRange());
+
   return true;
 }
 


        


More information about the cfe-commits mailing list