Question

I am working on a c++ project where I would like to use the rapidxml library. The library can be found here: http://rapidxml.sourceforge.net/ I downloaded this (4 source code files .hpp) and was able to compile the project on my windows machine with the CodeBlocks IDE.

However, when I attempted to build this on the linux machine at school, it showed the following error messages and would not compile successfully

I am not sure what the problem is and how I can avoid these errors/warnings.

/mydirectory/rapidxml.hpp: In constructor 'rapidxml::parse_error::parse_error(const char*, void*)':
/mydirectory/rapidxml.hpp:78:13: error: declaration of 'where' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:78:13: error: declaration of 'what' shadows a member of 'this' [-Werror=shadow]
In file included from /mydirectory/VmapXmlParser.h:10:0,
                 from /projectFolder/VmapXmlParser.cpp:1:
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::name(const Ch*, std::size_t)':
/mydirectory/rapidxml.hpp:722:9: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::name(const Ch*)':
/mydirectory/rapidxml.hpp:731:9: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::value(const Ch*, std::size_t)':
/mydirectory/rapidxml.hpp:752:9: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::value(const Ch*)':
/mydirectory/rapidxml.hpp:761:9: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In constructor 'rapidxml::xml_node<Ch>::xml_node(rapidxml::node_type)':
/mydirectory/rapidxml.hpp:902:13: error: declaration of 'type' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_node<Ch>::type(rapidxml::node_type)':
/mydirectory/rapidxml.hpp:1066:9: error: declaration of 'type' shadows a member of 'this' [-Werror=shadow]
In file included from /mydirectory/VmapXmlParser.h:11:0,
                 from /projectFolder/VmapXmlParser.cpp:1:
/mydirectory/rapidxml_utils.hpp: In constructor 'rapidxml::file<Ch>::file(const char*)':
/mydirectory/rapidxml_utils.hpp:40:20: error: declaration of 'size' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml_utils.hpp: In constructor 'rapidxml::file<Ch>::file(const char*) [with Ch = char]':
/projectFolder/VmapXmlParser.cpp:29:46:   instantiated from here
/mydirectory/rapidxml_utils.hpp:40:40: error: declaration of 'size' shadows a member of 'this' [-Werror=shadow]
In file included from /mydirectory/VmapXmlParser.h:10:0,
                 from /projectFolder/VmapXmlParser.cpp:1:
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_node<Ch>::first_node(const Ch*, std::size_t, bool) const [with Ch = char, std::size_t = unsigned int]':
/projectFolder/VmapXmlParser.cpp:36:55:   instantiated from here
/mydirectory/rapidxml.hpp:936:23: error: declaration of 'name_size' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:936:23: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_node<Ch>::next_sibling(const Ch*, std::size_t, bool) const [with Ch = char, std::size_t = unsigned int]':
/projectFolder/VmapXmlParser.cpp:41:35:   instantiated from here
/mydirectory/rapidxml.hpp:1004:23: error: declaration of 'name_size' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:1004:23: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_attribute<Ch>* rapidxml::xml_node<Ch>::first_attribute(const Ch*, std::size_t, bool) const [with Ch = char, std::size_t = unsigned int]':
/projectFolder/VmapXmlParser.cpp:48:60:   instantiated from here
/mydirectory/rapidxml.hpp:1025:28: error: declaration of 'name_size' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:1025:28: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_attribute<Ch>* rapidxml::xml_attribute<Ch>::next_attribute(const Ch*, std::size_t, bool) const [with Ch = char, std::size_t = unsigned int]':
/projectFolder/VmapXmlParser.cpp:48:97:   instantiated from here
/mydirectory/rapidxml.hpp:856:28: error: declaration of 'name_size' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:856:28: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In constructor 'rapidxml::xml_node<Ch>::xml_node(rapidxml::node_type) [with Ch = char]':
/mydirectory/rapidxml.hpp:1365:41:   instantiated from 'rapidxml::xml_document<Ch>::xml_document() [with Ch = char]'
/projectFolder/VmapXmlParser.cpp:30:30:   instantiated from here
/mydirectory/rapidxml.hpp:901:9: error: declaration of 'type' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:2114:17: error: switch missing default case [-Werror=switch-default]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:2043:24: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_pi(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2107:48:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:1889:28: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:1899:29: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_comment(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2123:57:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:1790:25: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_cdata(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2134:55:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:2015:25: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_doctype(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2146:57:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:1817:25: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:1834:25: error: switch missing default case [-Werror=switch-default]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::name(const Ch*, std::size_t) [with Ch = char, std::size_t = unsigned int]':
/mydirectory/rapidxml.hpp:2047:13:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:721:14: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_document<Ch>::parse_node_attributes(Ch*&, rapidxml::xml_node<Ch>*) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2053:13:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:2243:28: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:2053:13:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:2276:29: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::value(const Ch*, std::size_t) [with Ch = char, std::size_t = unsigned int]':
/mydirectory/rapidxml.hpp:1910:17:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_pi(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2107:48:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:751:14: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void* rapidxml::memory_pool<Ch>::allocate_aligned(std::size_t) [with Ch = char, std::size_t = unsigned int]':
/mydirectory/rapidxml.hpp:419:65:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::memory_pool<Ch>::allocate_node(rapidxml::node_type, const Ch*, const Ch*, std::size_t, std::size_t) [with Ch = char, std::size_t = unsigned int]'
/mydirectory/rapidxml.hpp:2040:69:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:618:69: error: cast from 'char*' to 'rapidxml::memory_pool<char>::header*' increases required alignment of target type [-Werror=cast-align]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::name(const Ch*) [with Ch = char]':
/mydirectory/rapidxml.hpp:426:21:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::memory_pool<Ch>::allocate_node(rapidxml::node_type, const Ch*, const Ch*, std::size_t, std::size_t) [with Ch = char, std::size_t = unsigned int]'
/mydirectory/rapidxml.hpp:2040:69:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:730:14: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::value(const Ch*) [with Ch = char]':
/mydirectory/rapidxml.hpp:433:21:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::memory_pool<Ch>::allocate_node(rapidxml::node_type, const Ch*, const Ch*, std::size_t, std::size_t) [with Ch = char, std::size_t = unsigned int]'
/mydirectory/rapidxml.hpp:2040:69:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:760:14: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'Ch rapidxml::xml_document<Ch>::parse_and_append_data(rapidxml::xml_node<Ch>*, Ch*&, Ch*) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2228:21:   instantiated from 'void rapidxml::xml_document<Ch>::parse_node_contents(Ch*&, rapidxml::xml_node<Ch>*) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2059:17:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
Was it helpful?

Solution

You're using GCC with strict options which turn certain (or maybe all) warning messages into errors.

Example - here's the errors:-

rapidxml.hpp: In constructor 'rapidxml::parse_error::parse_error(const char*, void*)':
rapidxml.hpp:78:13: error: declaration of 'where' shadows a member of 'this'
[-Werror=shadow]
rapidxml.hpp:78:13: error: declaration of 'what' shadows a member of 'this'
[-Werror=shadow]

... and here's the code

class parse_error: public std::exception
{
public:
    //! Constructs parse error
    parse_error(const char *what, void *where)
        : m_what(what)
        , m_where(where)
    {
    }

The 'problem' is that GCC thinks the code might be wrong because what and where are used as names of parameters in the constructor - but they're also defined as member functions of the base class. (std::exception).

This is perfectly valid C++ and will work just fine. GCC is just configured to be ultra-picky. You'll need to add the option -Wno-error=shadow to stop these warnings being treated as errors.

http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top