Code cleanup to pass gcc -Weffc++ warnings

This commit is contained in:
Thierry Lelegard 2017-09-01 10:14:16 +02:00
parent dbf18add4c
commit 7f0f754cb7
4 changed files with 38 additions and 20 deletions

View File

@ -1,3 +1,10 @@
# Extended C++ warning policy
CXXFLAGS += -Werror -Wall -Wextra -Wshadow -Wpedantic -Wformat-nonliteral \
-Wformat-security -Wswitch-default -Wuninitialized -Wundef \
-Wpointer-arith -Woverloaded-virtual -Wctor-dtor-privacy \
-Wnon-virtual-dtor -Woverloaded-virtual -Wsign-promo \
-Wno-unused-parameter -Weffc++
all: xmltest staticlib all: xmltest staticlib
rebuild: clean all rebuild: clean all

View File

@ -741,6 +741,7 @@ bool XMLDocument::Accept( XMLVisitor* visitor ) const
XMLNode::XMLNode( XMLDocument* doc ) : XMLNode::XMLNode( XMLDocument* doc ) :
_document( doc ), _document( doc ),
_parent( 0 ), _parent( 0 ),
_value(),
_parseLineNum( 0 ), _parseLineNum( 0 ),
_firstChild( 0 ), _lastChild( 0 ), _firstChild( 0 ), _lastChild( 0 ),
_prev( 0 ), _next( 0 ), _prev( 0 ), _next( 0 ),
@ -1993,9 +1994,16 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) :
_processEntities( processEntities ), _processEntities( processEntities ),
_errorID(XML_SUCCESS), _errorID(XML_SUCCESS),
_whitespaceMode( whitespaceMode ), _whitespaceMode( whitespaceMode ),
_errorStr1(),
_errorStr2(),
_errorLineNum( 0 ), _errorLineNum( 0 ),
_charBuffer( 0 ), _charBuffer( 0 ),
_parseCurLineNum( 0 ) _parseCurLineNum( 0 ),
_unlinked(),
_elementPool(),
_attributePool(),
_textPool(),
_commentPool()
{ {
// avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+) // avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+)
_document = this; _document = this;
@ -2367,12 +2375,14 @@ void XMLDocument::Parse()
XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) : XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) :
_elementJustOpened( false ), _elementJustOpened( false ),
_stack(),
_firstElement( true ), _firstElement( true ),
_fp( file ), _fp( file ),
_depth( depth ), _depth( depth ),
_textDepth( -1 ), _textDepth( -1 ),
_processEntities( true ), _processEntities( true ),
_compactMode( compact ) _compactMode( compact ),
_buffer()
{ {
for( int i=0; i<ENTITY_RANGE; ++i ) { for( int i=0; i<ENTITY_RANGE; ++i ) {
_entityFlag[i] = false; _entityFlag[i] = false;

View File

@ -192,10 +192,11 @@ template <class T, int INITIAL_SIZE>
class DynArray class DynArray
{ {
public: public:
DynArray() { DynArray() :
_mem = _pool; _mem( _pool ),
_allocated = INITIAL_SIZE; _allocated( INITIAL_SIZE ),
_size = 0; _size( 0 )
{
} }
~DynArray() { ~DynArray() {
@ -333,7 +334,7 @@ template< int ITEM_SIZE >
class MemPoolT : public MemPool class MemPoolT : public MemPool
{ {
public: public:
MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
~MemPoolT() { ~MemPoolT() {
Clear(); Clear();
} }
@ -1211,7 +1212,7 @@ public:
private: private:
enum { BUF_SIZE = 200 }; enum { BUF_SIZE = 200 };
XMLAttribute() : _parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {} XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
virtual ~XMLAttribute() {} virtual ~XMLAttribute() {}
XMLAttribute( const XMLAttribute& ); // not supported XMLAttribute( const XMLAttribute& ); // not supported
@ -1947,16 +1948,13 @@ class TINYXML2_LIB XMLHandle
{ {
public: public:
/// Create a handle from any node (at any depth of the tree.) This can be a null pointer. /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
XMLHandle( XMLNode* node ) { XMLHandle( XMLNode* node ) : _node( node ) {
_node = node;
} }
/// Create a handle from a node. /// Create a handle from a node.
XMLHandle( XMLNode& node ) { XMLHandle( XMLNode& node ) : _node( &node ) {
_node = &node;
} }
/// Copy constructor /// Copy constructor
XMLHandle( const XMLHandle& ref ) { XMLHandle( const XMLHandle& ref ) : _node( ref._node ) {
_node = ref._node;
} }
/// Assignment /// Assignment
XMLHandle& operator=( const XMLHandle& ref ) { XMLHandle& operator=( const XMLHandle& ref ) {
@ -2030,14 +2028,11 @@ private:
class TINYXML2_LIB XMLConstHandle class TINYXML2_LIB XMLConstHandle
{ {
public: public:
XMLConstHandle( const XMLNode* node ) { XMLConstHandle( const XMLNode* node ) : _node( node ) {
_node = node;
} }
XMLConstHandle( const XMLNode& node ) { XMLConstHandle( const XMLNode& node ) : _node( &node ) {
_node = &node;
} }
XMLConstHandle( const XMLConstHandle& ref ) { XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) {
_node = ref._node;
} }
XMLConstHandle& operator=( const XMLConstHandle& ref ) { XMLConstHandle& operator=( const XMLConstHandle& ref ) {
@ -2252,6 +2247,10 @@ private:
bool _restrictedEntityFlag[ENTITY_RANGE]; bool _restrictedEntityFlag[ENTITY_RANGE];
DynArray< char, 20 > _buffer; DynArray< char, 20 > _buffer;
// Prohibit cloning, intentionally not implemented
XMLPrinter( const XMLPrinter& );
XMLPrinter& operator=( const XMLPrinter& );
}; };

View File

@ -2017,6 +2017,8 @@ int main( int argc, const char ** argv )
{ {
struct TestUtil: XMLVisitor struct TestUtil: XMLVisitor
{ {
TestUtil() : str() {}
void TestParseError(const char *testString, const char *docStr, XMLError expected_error, int expectedLine) void TestParseError(const char *testString, const char *docStr, XMLError expected_error, int expectedLine)
{ {
XMLDocument doc; XMLDocument doc;