This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Namespace + STL internal error


hi,

Playing with namespace and STL I made the namespace the same as a stl
`set' object in a class. The attached file shows the error in about as
small a file I can. To see no error remove the SHOW_ERROR define.

I checked the known bug list and could not see it.

I am not on this bugs list.

Regards

-- 
 Chris Johns, mailto:ccj@acm.org
//
// This is a single test file from Chris Johns (ccj@acm.org).
//
// Internal Compiler error on :
//
// $ g++ -v
// Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
// gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) 
//
// $ uname -a
// Linux kiwi.ods.com.au 2.2.12-20 #1 Mon Sep 27 10:40:35 EDT 1999 i686 unknown
//
// Compile with :
// 
//  g++ -g -o test test.cpp
//  test.cpp: In function `class ostream & operator <<<::foos::B>(class\
//                     ostream &, const class ::foos::::foos::A<::foos::B> &)':
//  test.cpp:100:   instantiated from here
//  test.cpp:51: Internal compiler error.
//  test.cpp:51: Please submit a full bug report to `egcs-bugs@egcs.cygnus.com'.
//  test.cpp:51: See <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.
//

#include <algorithm>
#include <set>
#include <string>
#include <iostream>

#define SHOW_ERROR

#if defined (SHOW_ERROR)
namespace foos
#else
namespace c
#endif
{
  
  template <class T> 
  class A
  {
  public:

    struct ltint {
      bool operator() (const T* t1, const T* t2) const {
        return t1->id () < t2->id ();
      }
    };
  
    set<T*, ltint> foos;
  
  };

  template <class T>
  inline ostream& operator<< (ostream& s, const A<T>& o) {
    copy (o.foos.begin (), o.foos.end (), 
          ostream_iterator<T*> (s, "\n"));
    return s;
  }

  class B
  {
  public:

    B (const string& _label, const int _id)
      : _label (_label), _id (_id) {}
  
    const string& label () const {
      return _label; 
    }

    const int id () const {
      return _id;
    }
    
  private:

    const string _label;
    const int  _id;
  
  };

  inline ostream& operator<< (ostream& s, const B* b) {
    s << "label:`" << b->label () << "`,sorder:" << b->id ();
    return s;
  }

  A<B> ab;

}

#if defined (SHOW_ERROR)
using namespace foos;
#else
using namespace c;
#endif

int main ()
{
  B b2 ("two", 2);
  B b1 ("one", 1);

  ab.foos.insert (&b1);
  ab.foos.insert (&b2);
  
  cout << ab;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]