]> granicus.if.org Git - clang/commitdiff
Deallocate the BasePaths structure that we allocate for LookupResult.
authorDouglas Gregor <dgregor@apple.com>
Thu, 15 Jan 2009 02:19:31 +0000 (02:19 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 15 Jan 2009 02:19:31 +0000 (02:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62250 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaLookup.cpp

index eb718f7f1ad1099756e67b19895354142c87721a..cf9f8502c722708e2c91729b9ba04e9e544f203c 100644 (file)
@@ -638,7 +638,11 @@ public:
       /// by the LookupResult. Last is non-zero to indicate that the
       /// ambiguity is caused by two names found in base class
       /// subobjects of different types.
-      AmbiguousLookup
+      AmbiguousLookup,
+
+      /// We've moved from this object. There should not be any
+      /// attempts to look at its state.
+      Dead
     } StoredKind;
 
     /// The first lookup result, whose contents depend on the kind of
@@ -706,7 +710,9 @@ public:
       AmbiguousBaseSubobjects
     };
 
-    LookupResult() : StoredKind(SingleDecl), First(0), Last(0), Context(0) { }
+    LookupResult() : StoredKind(Dead), First(0), Last(0), Context(0) { }
+
+    LookupResult(const LookupResult& Other);
 
     LookupResult(ASTContext &Context, Decl *D) 
       : StoredKind(SingleDecl), First(reinterpret_cast<uintptr_t>(D)),
@@ -725,6 +731,10 @@ public:
         Last(DifferentSubobjectTypes? 1 : 0),
         Context(&Context) { }
 
+    ~LookupResult();
+
+    LookupResult& operator=(const LookupResult& Other);
+
     LookupKind getKind() const;
 
     /// @brief Determine whether name look found something.
index b85824382bf4162f7a6c57d42da53a29a4f57419..cc9a36ced223c1da40f71ffd3c5f22bef45b6220 100644 (file)
@@ -127,6 +127,15 @@ bool Sema::LookupCriteria::isLookupResult(Decl *D) const {
   return false;
 }
 
+/// @brief Moves the name-lookup results from Other to the
+/// newly-constructed LookupResult.
+Sema::LookupResult::LookupResult(const LookupResult& Other) 
+  : StoredKind(Other.StoredKind), First(Other.First), Last(Other.Last),
+    Context(Other.Context) {
+  Other.StoredKind = Dead;
+}
+
+/// @brief Moves the name-lookup results from Other to this LookupResult.
 Sema::LookupResult::LookupResult(ASTContext &Context, 
                                  IdentifierResolver::iterator F, 
                                  IdentifierResolver::iterator L)
@@ -167,6 +176,25 @@ Sema::LookupResult::LookupResult(ASTContext &Context,
   Last = 0;
 }
 
+Sema::LookupResult::~LookupResult() {
+  if (StoredKind == AmbiguousLookup)
+    delete getBasePaths();
+}
+
+Sema::LookupResult& Sema::LookupResult::operator=(const LookupResult& Other) {
+  if (StoredKind == AmbiguousLookup)
+    delete getBasePaths();
+
+  StoredKind = Other.StoredKind;
+  First = Other.First;
+  Last = Other.Last;
+  Context = Other.Context;
+
+  Other.StoredKind = Dead;
+  return *this;
+}
+
+
 /// @brief Determine the result of name lookup.
 Sema::LookupResult::LookupKind Sema::LookupResult::getKind() const {
   switch (StoredKind) {
@@ -179,6 +207,10 @@ Sema::LookupResult::LookupKind Sema::LookupResult::getKind() const {
 
   case AmbiguousLookup:
     return Last? AmbiguousBaseSubobjectTypes : AmbiguousBaseSubobjects;
+
+  case Dead:
+    assert(false && "Attempt to look at a dead LookupResult");
+    break;
   }
 
   // We can't ever get here.
@@ -217,6 +249,9 @@ Decl *Sema::LookupResult::getAsDecl() const {
     assert(false && 
            "Name lookup returned an ambiguity that could not be handled");
     break;
+
+  case Dead:
+    assert(false && "Attempt to look at a dead LookupResult");
   }
 
   return 0;