🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

templates cause bogus undeclared identifier error

#1345
From: James Clark
Date: Thu, 07 Jan 1993 09:57
66 lines
2134 bytes
$ cat bug3.cc
template<class T>
class List {
  struct Item {
    Item *next;
    T obj;
    Item(T t, Item *x = 0) : obj(t), next(x) { }
  };
  Item *head;
public:
  List() : head(0) {}
  friend class List_iter<T>;
};

template<class T>
class List_iter {
  List<T>::Item *head;
public:
  List_iter(const List<T> &x) : head(x.head) {}
  int done() const { return head == 0; }
  void next() { head = head->next; }
};

template<class T>
class Plist : private List<void *> {
public:
  Plist() {}
  friend class Plist_iter<T>;
};

template<class T>
class Plist_iter : private List_iter<void *> {
public:
  Plist_iter(const Plist<T> &pl) : List_iter<void *>(pl) { }
  List_iter<void *>::done;
  List_iter<void *>::next;
};

struct A {
  Plist<int> sets;
  void foo();
  void bar();
};
  
void A::foo()
{
  Plist_iter<int> iter(sets);
}

void A::bar()
{
  Plist_iter<int> iter(sets);
}

$ gcc -c -v bug3.cc
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/specs
gcc version 2.3.3
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix bug3.cc /usr/tmp/cca19164.i
GNU CPP version 2.3.3 (sparc)
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.3/cc1plus /usr/tmp/cca19164.i -quiet -dumpbase bug3.cc -version -o /usr/tmp/cca19164.s
GNU C++ version 2.3.3 (sparc) compiled by GNU C version 2.3.2.
bug3.cc: In method `void  A::foo ()':
bug3.cc:46: `sets' undeclared (first use this function)
bug3.cc:46: (Each undeclared identifier is reported only once
bug3.cc:46: for each function it appears in.)
$ 
Technical Details
Message-ID: <9301070957.AA19167@jclark.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!jclark.com!jjc

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!jclark.com!jjc
From: jjc@jclark.com (James Clark)
Subject: templates cause bogus undeclared identifier error
Message-ID: <9301070957.AA19167@jclark.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Thu, 7 Jan 1993 09:57:16 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 67