You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Irving Reid <ir...@nevex.com> on 2000/02/02 22:10:14 UTC

Xerces-C: compiler warnings from "g++ -Wall"

We're building an application in c++ on Linux. We began with the 
Xerces-C 1.0.1 release, but recently switched to the most recent CVS 
version.

On both versions, we are getting warnings from the compiler when we 
turn on strict warnings:

g++ -Wall -O -g -c Rule.cpp -o Rule.o
In file included from /usr/local/include/dom/DOM_NodeIterator.hpp:70,
                 from /usr/local/include/dom/DOM_Document.hpp:98,
                 from /usr/local/include/dom/DOM.hpp:80,
                 from RuleTree.h:10,
                 from Rule.cpp:6:
/usr/local/include/dom/DOM_NodeFilter.hpp:108: warning: `class 
DOM_NodeFilter' has virtual functions but non-virtual destructor
In file included from /usr/local/include/dom/DOM_Document.hpp:98,
                 from /usr/local/include/dom/DOM.hpp:80,
                 from RuleTree.h:10,
                 from Rule.cpp:6:
/usr/local/include/dom/DOM_NodeIterator.hpp:114: warning: `class 
DOM_NodeIterator' has virtual functions but non-virtual destructor
In file included from /usr/local/include/dom/DOM_Document.hpp:99,
                 from /usr/local/include/dom/DOM.hpp:80,
                 from RuleTree.h:10,
                 from Rule.cpp:6:
/usr/local/include/dom/DOM_TreeWalker.hpp:121: warning: `class 
DOM_TreeWalker' has virtual functions but non-virtual destructor

As I understand C++, the risk with the non-virtual destructor is that 
if you derive from the class and add data members, they may not get 
destroyed properly.

I can't find any places in the Xerces source where any of these are 
subclassed. Do they need to have virtual methods?

If they can be subclassed, the destructors should be defined virtual; 
otherwise, the methods should be changed to non-virtual.

 - irving -



Re: Xerces-C: compiler warnings from "g++ -Wall"

Posted by Andy Heninger <he...@us.ibm.com>.
Irving Reid <ir...@nevex.com> notes


> We're building an application in c++ on Linux. We began with the
> Xerces-C 1.0.1 release, but recently switched to the most recent CVS
> version.
>
> On both versions, we are getting warnings from the compiler when we
> turn on strict warnings:

[Problems with DOM_NodeFilter.hpp, DOM_NodeIterator.hpp, DOM_TreeWalker.hpp]


> As I understand C++, the risk with the non-virtual destructor is that
> if you derive from the class and add data members, they may not get
> destroyed properly.
>
> I can't find any places in the Xerces source where any of these are
> subclassed. Do they need to have virtual methods?
>
> If they can be subclassed, the destructors should be defined virtual;
> otherwise, the methods should be changed to non-virtual.
>

The NodeFilter, NodeIterator and TreeWalker classes are pretty badly
broken in their current incarnation. The mismatch between the non-virtual
destructors and the virtual methods is just one of many problems.

New code will be going in, I hope within a day or two.

DOM_NodeIterator and DOM_TreeWalker will lose their virtual functions.
They shouldn't have had them in the first place; they are like most
of the other DOM_* classes in they consist of nothing more than
a pointer to an implementation class.

DOM_NodeFilter is more like a conventional C++ class.  Application
programs must create a derived class inorder to use it, and
must explicitly new and delete instances themselves.  It will
retain its virtual functions, and the destructor will be virtual.

  -- Andy