This is the mail archive of the gcc@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]
Other format: [Raw text]

Incorrect C++ code or regression?


Hello everybody,

(Disclaimer: I do not understand C++ templates.)

I've tried to make a testcase from the original code.

GCC 3.3.5 compiles with no warning, while GCC 3.4.3 rejects it.

Can somebody tell me if it because the code is illegal, and GCC 3.4.3's stricter parser now rejects it, or is it some kind of regression?

$ g++-3.3.5 -c -Wall -ansi -pedantic foo.cxx
/* NO WARNING */

$ g++-3.4.3 -c -Wall -ansi -pedantic foo.cxx
foo.cxx: In member function `void WN_TREE_ITER< PRE_ORDER, WHIRL>::WN_TREE_next()':
foo.cxx:53: error: `_wn' undeclared (first use this function)
foo.cxx:53: error: (Each undeclared identifier is reported only once for each function it appears in.)


$ cat foo.cxx
typedef int WN;

typedef struct wn_iter {
  WN *wn;               /* current tree node */
} WN_ITER;

enum TRAV_ORDER {
  PRE_ORDER=0,
  POST_ORDER=1
};

// ======================================================================
// Base class shared by both traversal order interators
// We need this to get partial specialization work
// ======================================================================

template <typename WHIRL>
class WN_TREE_ITER_base
{
protected:
  WHIRL                        _wn;     // whirl node to iterate over;

public:
  WHIRL Wn(void)                        const      {return _wn;}
  void Set_wn(WHIRL wn2)                           { _wn = wn2;}
  WN_TREE_ITER_base(): _wn(0)    {}
  WN_TREE_ITER_base (WHIRL wn2) : _wn(wn2) {}
}; // class WN_TREE_ITER_base

// dummy template to parameterize the traversal order.
// only the specialized versions defined below are used.
template <TRAV_ORDER order, class WHIRL = WN*>
class WN_TREE_ITER : public WN_TREE_ITER_base<WHIRL>
{
}; // WN_TREE_ITER

// ======================================================================
// preorder traversal iterator
// ======================================================================
template <typename WHIRL>
class WN_TREE_ITER<PRE_ORDER, WHIRL> : public WN_TREE_ITER_base<WHIRL>
{
public:
  WN_TREE_ITER () : WN_TREE_ITER_base<WHIRL> () {}
  WN_TREE_ITER (WHIRL wn) : WN_TREE_ITER_base<WHIRL> (wn) {}
  void WN_TREE_next ();                 // next for preorder
}; // WN_TREE_ITER<PRE_ORDER, WHIRL>

template <class WHIRL>
void
WN_TREE_ITER<PRE_ORDER, WHIRL>::WN_TREE_next ()
{
  if (_wn == 0) return;
}

--
Regards, Grumble


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