]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Avoid endless loop inheriting interfaces.
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 24 Dec 2010 00:13:35 +0000 (00:13 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 24 Dec 2010 00:13:35 +0000 (00:13 +0000)
From-SVN: r168216

gcc/go/gofrontend/types.cc

index 17399659e4cf04166891e3dad3a8abb06ce2b5af..2278c9426ff81ef228079f2ed14298b81bc7cad1 100644 (file)
@@ -5548,7 +5548,7 @@ Interface_type::finalize_methods()
       const Typed_identifier* p = &this->methods_->at(from);
       if (!p->name().empty())
        {
-         size_t i = 0;
+         size_t i;
          for (i = 0; i < to; ++i)
            {
              if (this->methods_->at(i).name() == p->name())
@@ -5594,7 +5594,30 @@ Interface_type::finalize_methods()
           q != methods->end();
           ++q)
        {
-         if (q->name().empty() || this->find_method(q->name()) == NULL)
+         if (q->name().empty())
+           {
+             if (q->type() == p->type())
+               error_at(p->location(), "interface inheritance loop");
+             else
+               {
+                 size_t i;
+                 for (i = from + 1; i < this->methods_->size(); ++i)
+                   {
+                     const Typed_identifier* r = &this->methods_->at(i);
+                     if (r->name().empty() && r->type() == q->type())
+                       {
+                         error_at(p->location(),
+                                  "inherited interface listed twice");
+                         break;
+                       }
+                   }
+                 if (i == this->methods_->size())
+                   this->methods_->push_back(Typed_identifier(q->name(),
+                                                              q->type(),
+                                                              p->location()));
+               }
+           }
+         else if (this->find_method(q->name()) == NULL)
            this->methods_->push_back(Typed_identifier(q->name(), q->type(),
                                                       p->location()));
          else