🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1362

Problem with Template formal parameter namespace

#1362
From: Michael Schwartz
Date: Thu, 07 Jan 1993 21:59
73 lines
2371 bytes
GCC 2.3.3

I have had this problem since version 2.2, but worked around it.
Please consider fixing or caveating this problem.

I'm sorry that the example is so crude.  I hope it illustrates the
problem well enough

Output of g++ -c -v bad_gcc.cc:

Reading specs from /usr/local/lib/gcc-lib/m68k-sun-sunos4.1/2.3.3/specs
gcc version 2.3.3
 /usr/local/lib/gcc-lib/m68k-sun-sunos4.1/2.3.3/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__mc68000 -D__sun -D__unix -D__HAVE_68881__ -D__mc68020__ -Dmc68020 bad_gcc3.cc /usr/tmp/cca10005.i
GNU CPP version 2.3.3 (68k, MIT syntax)
 /usr/local/lib/gcc-lib/m68k-sun-sunos4.1/2.3.3/cc1plus /usr/tmp/cca10005.i -quiet -dumpbase bad_gcc3.cc -version -o /usr/tmp/cca10005.s
GNU C++ version 2.3.3 (68k, MIT syntax) compiled by GNU C version 2.3.3.
bad_gcc3.cc: In method `int  C::Get_Reading (class A*&)':
bad_gcc3.cc:43: Internal compiler error.
bad_gcc3.cc:43: Please report this to `bug-g++@prep.ai.mit.edu'.

bad_gcc.cc:

// Use of T as template parameter clashes with uses as class member
template <class T> class D
{
  public:
    D () { storage = 0; }
    ~D () {}
    T& operator [] ( unsigned i ) { return *storage; }
    int sizeOf() { return 1; }
  private:
    T *storage;
};

class A
{
  public:
    A(void) {}
    ~A(void) {}
};

// THIS DOESN'T WORK!  IT HAS TROUBLE WITH FORMAL TEMPLATE
// PARAMETERS WHICH MATCH CLASS MEMBER NAMES
// BUT, IF YOU DEFINE WORKAROUND, IT COMPILES FINE!
#ifdef WORKAROUND
#define T X
#endif
class C
{
  public:
    C() {}
    ~C() {}
    int Get_Reading  (A *&);
  private:
    D<A *> T;
    int curindex;
};

int C::Get_Reading (A *&pa)
{
  int max = T.sizeOf();
  for (curindex = 0; curindex < max; curindex++)
    if (T[curindex] != 0)
    {
      pa = T[curindex];
      return 1;
    }
  return 0;
}

main()
{
}
Technical Details
Message-ID: <9301072259.AA10018@loki.den.mmc.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!loki-gw.den.mmc.com!schwartz

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!loki-gw.den.mmc.com!schwartz
From: schwartz@loki-gw.den.mmc.com (  Michael Schwartz)
Subject: Problem with Template formal parameter namespace
Message-ID: <9301072259.AA10018@loki.den.mmc.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Thu, 7 Jan 1993 21:59:25 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 74