[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#119635: g++ Internal compiler error 19970302



> I think it's probably best to wait with forwarding until Matthias or Martin
> have had a chance to look at this.

It's an ICE, so there is definitely a compiler bug. Since it also
occurs on all versions, it should be forwarded upstream; Matthias will
certainly do that.

Of course, there are a number of errors in this file also; if they are
corrected, it compiles fine:

1. A template specialization is denoted by

   template<> class Stump<Bounds2D> {

   not just

   class Stump<Bounds2D> {

2. Accessing a member in a template does not automatically search base
   types. Instead, it is a dependent name, and must be qualified with
   the base type (to delay name lookup to the point of instantiation).
   IOW, write

   TreeImpl<Shape> *m_branch[Stump<Shape>::m_numBranches];

   not

   TreeImpl<Shape> *m_branch[m_numBranches];

3. The size of an array must be an integral constant expression.
    A variable is only a constant expression if it is "const" *and*
    if it is initialized with an integral constant expression.
    So doing

      // This class originally from a header, the constant is initialized
      // in a different .cpp file
      const static int m_numBranches;

    is incorrect; if you want to use m_numBranches in a class, you
    *must* initialize the member with its value. If you write

      const static int m_numBranches = 100;

    instead.

4. Explicit specializations of member templates must be preceded by
   template<> also. I.e. don't write

   int TreeImpl<Bounds2D>::getBranchNumber(TreeImpl<Bounds2D> *t) {return -1;}

   but write

   template<>
   int TreeImpl<Bounds2D>::getBranchNumber(TreeImpl<Bounds2D> *t) {return -1;}

With all these changes, your code compiles fine.

Regards,
Martin



Reply to: