Illegal code?

G

Grumble

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. Could
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;
}
 
G

Gianni Mariani

Grumble said:
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. Could
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?

I think the compiler is right. GCC I believe was `fixed' to make
identifiers in templates require dependantcy (if need be). Don't know
for sure but I recall `fixing' a number of these...
template <class WHIRL>
void
WN_TREE_ITER<PRE_ORDER, WHIRL>::WN_TREE_next ()
{
if (_wn == 0) return;

if (this->_wn == 0) return;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top