This is the mail archive of the gcc-bugs@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]

Code compiled fine under 2.8.1 but fails to compile under 2.95.1


We have some code that compiled fine under 2.8.1 but fails to compile
successfully under 2.95.1. I have included a sample of code below that
exhibits the problem.

If you replace the destructor with a different member (say a function named
fred), then there is no compiler error.  The error is not dependent on the
destructor being virtual.  The engineer who developed the code looked at (a
reasonably recent draft of) the ANSI C++ standard, and could find no
restriction on declaration of out of line functions in a template class.

Tom

CODE
----

// Start fo foo.cpp

typedef int KeyValueTYP;
class BalancedTreeBase
{
protected:
  BalancedTreeBase( KeyValueTYP _key );
  virtual ~BalancedTreeBase() { }
private:
  BalancedTreeBase();
};

template <class T>
class BalancedTreeNode : private BalancedTreeBase
{
public:
  BalancedTreeNode( KeyValueTYP _key ) : BalancedTreeBase( _key ) { }
  virtual ~BalancedTreeNode();
};

class Name;
typedef BalancedTreeNode<Name>            NameTreeNode;
// Adding this forward declaration eliminates the error.
//BalancedTreeNode<Name>::~BalancedTreeNode();

class Name 
{
public:
  Name( KeyValueTYP numericName) : aliasNamespaceNode( numericName) { }
  ~Name() { }
private:
  NameTreeNode              aliasNamespaceNode;
};

// Commenting out class Name, and declaring foo doesn't generate the error.
//NameTreeNode foo(37);

BalancedTreeNode<Name>::~BalancedTreeNode()
{
}

// end of foo.cpp


USAGE
-----

2.95.1

bash.exe-2.02$ e:/usr/local/powerpc-motorola-elf/bin/powerpc-elf-gcc.exe -v
Reading specs from /usr/local/powerpc-motorola-elf/lib/gcc-lib/powerpc-motorola-elf/2.95.1/specs
gcc version 2.95.1 19990816 (release)
bash.exe-2.02$ e:/usr/local/powerpc-motorola-elf/bin/powerpc-elf-gcc.exe -c foo.cpp
foo.cpp:37: specialization of BalancedTreeNode<Name>::~BalancedTreeNode() after instantiation
foo.cpp:37: prototype for `BalancedTreeNode<Name>::~BalancedTreeNode<Name>()' does not match any in class `BalancedTreeNode<Name>'
foo.cpp:16: candidate is: BalancedTreeNode<Name>::~BalancedTreeNode()


2.8.1

bash.exe-2.02$ powerpc-elf-gcc.exe -v
Reading specs from \\c\packages\gnu_powerpc\lib\gcc-lib\powerpc-elf\2.8.1\specs
gcc version 2.8.1
bash.exe-2.02$ powerpc-elf-gcc.exe -c foo.cpp
bash.exe-2.02$ 


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