Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup to pass gcc -Weffc++ warnings #617

Merged
merged 1 commit into from Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
@@ -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

rebuild: clean all
Expand Down
14 changes: 12 additions & 2 deletions tinyxml2.cpp
Expand Up @@ -741,6 +741,7 @@ bool XMLDocument::Accept( XMLVisitor* visitor ) const
XMLNode::XMLNode( XMLDocument* doc ) :
_document( doc ),
_parent( 0 ),
_value(),
_parseLineNum( 0 ),
_firstChild( 0 ), _lastChild( 0 ),
_prev( 0 ), _next( 0 ),
Expand Down Expand Up @@ -1993,9 +1994,16 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) :
_processEntities( processEntities ),
_errorID(XML_SUCCESS),
_whitespaceMode( whitespaceMode ),
_errorStr1(),
_errorStr2(),
_errorLineNum( 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+)
_document = this;
Expand Down Expand Up @@ -2367,12 +2375,14 @@ void XMLDocument::Parse()

XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) :
_elementJustOpened( false ),
_stack(),
_firstElement( true ),
_fp( file ),
_depth( depth ),
_textDepth( -1 ),
_processEntities( true ),
_compactMode( compact )
_compactMode( compact ),
_buffer()
{
for( int i=0; i<ENTITY_RANGE; ++i ) {
_entityFlag[i] = false;
Expand Down
35 changes: 17 additions & 18 deletions tinyxml2.h
Expand Up @@ -192,10 +192,11 @@ template <class T, int INITIAL_SIZE>
class DynArray
{
public:
DynArray() {
_mem = _pool;
_allocated = INITIAL_SIZE;
_size = 0;
DynArray() :
_mem( _pool ),
_allocated( INITIAL_SIZE ),
_size( 0 )
{
}

~DynArray() {
Expand Down Expand Up @@ -333,7 +334,7 @@ template< int ITEM_SIZE >
class MemPoolT : public MemPool
{
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() {
Clear();
}
Expand Down Expand Up @@ -1211,7 +1212,7 @@ class TINYXML2_LIB XMLAttribute
private:
enum { BUF_SIZE = 200 };

XMLAttribute() : _parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
virtual ~XMLAttribute() {}

XMLAttribute( const XMLAttribute& ); // not supported
Expand Down Expand Up @@ -1947,16 +1948,13 @@ class TINYXML2_LIB XMLHandle
{
public:
/// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
XMLHandle( XMLNode* node ) {
_node = node;
XMLHandle( XMLNode* node ) : _node( node ) {
}
/// Create a handle from a node.
XMLHandle( XMLNode& node ) {
_node = &node;
XMLHandle( XMLNode& node ) : _node( &node ) {
}
/// Copy constructor
XMLHandle( const XMLHandle& ref ) {
_node = ref._node;
XMLHandle( const XMLHandle& ref ) : _node( ref._node ) {
}
/// Assignment
XMLHandle& operator=( const XMLHandle& ref ) {
Expand Down Expand Up @@ -2030,14 +2028,11 @@ class TINYXML2_LIB XMLHandle
class TINYXML2_LIB XMLConstHandle
{
public:
XMLConstHandle( const XMLNode* node ) {
_node = node;
XMLConstHandle( const XMLNode* node ) : _node( node ) {
}
XMLConstHandle( const XMLNode& node ) {
_node = &node;
XMLConstHandle( const XMLNode& node ) : _node( &node ) {
}
XMLConstHandle( const XMLConstHandle& ref ) {
_node = ref._node;
XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) {
}

XMLConstHandle& operator=( const XMLConstHandle& ref ) {
Expand Down Expand Up @@ -2252,6 +2247,10 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor
bool _restrictedEntityFlag[ENTITY_RANGE];

DynArray< char, 20 > _buffer;

// Prohibit cloning, intentionally not implemented
XMLPrinter( const XMLPrinter& );
XMLPrinter& operator=( const XMLPrinter& );
};


Expand Down
2 changes: 2 additions & 0 deletions xmltest.cpp
Expand Up @@ -2017,6 +2017,8 @@ int main( int argc, const char ** argv )
{
struct TestUtil: XMLVisitor
{
TestUtil() : str() {}

void TestParseError(const char *testString, const char *docStr, XMLError expected_error, int expectedLine)
{
XMLDocument doc;
Expand Down