xpath.c: warning: comparison of two values with different enumeration types ('xmlElementType' and 'xmlXPathTypeVal') [-Wenum-compare]
Commit b2189571 papered over the following warning when building libxml2 with clang and -Wenum-compare
(line number below may differ from master):
xpath.c:12439:28: warning: comparison of two values with different enumeration types ('xmlElementType' and 'xmlXPathTypeVal') [-Wenum-compare]
} else if (cur->type == type) {
~~~~~~~~~ ^ ~~~~
The part of the commit that suppressed this warning looks like this:
diff --git a/xpath.c b/xpath.c
index a9f29685..5211b126 100644
--- a/xpath.c
+++ b/xpath.c
@@ -12386,7 +12386,7 @@ xmlXPathNodeCollectAndTest(xmlXPathParserContextPtr ctxt,
default:
break;
}
- } else if (cur->type == type) {
+ } else if (cur->type == (xmlElementType) type) {
if (cur->type == XML_NAMESPACE_DECL)
XP_TEST_HIT_NS
else
However, the xmlElementType
and xmlXPathTypeVal
enums represent completely different state:
Definition of xmlElementType
from tree.h
:
typedef enum {
XML_ELEMENT_NODE= 1,
XML_ATTRIBUTE_NODE= 2,
XML_TEXT_NODE= 3,
XML_CDATA_SECTION_NODE= 4,
XML_ENTITY_REF_NODE= 5,
XML_ENTITY_NODE= 6,
XML_PI_NODE= 7,
XML_COMMENT_NODE= 8,
XML_DOCUMENT_NODE= 9,
XML_DOCUMENT_TYPE_NODE= 10,
XML_DOCUMENT_FRAG_NODE= 11,
XML_NOTATION_NODE= 12,
XML_HTML_DOCUMENT_NODE= 13,
XML_DTD_NODE= 14,
XML_ELEMENT_DECL= 15,
XML_ATTRIBUTE_DECL= 16,
XML_ENTITY_DECL= 17,
XML_NAMESPACE_DECL= 18,
XML_XINCLUDE_START= 19,
XML_XINCLUDE_END= 20
#ifdef LIBXML_DOCB_ENABLED
,XML_DOCB_DOCUMENT_NODE= 21
#endif
} xmlElementType;
Definition of xmlXPathTypeVal
from xpath.c
:
typedef enum {
NODE_TYPE_NODE = 0,
NODE_TYPE_COMMENT = XML_COMMENT_NODE,
NODE_TYPE_TEXT = XML_TEXT_NODE,
NODE_TYPE_PI = XML_PI_NODE
} xmlXPathTypeVal;
The current code was introduced in June 2006 with commit 9bca933a by Kasimier T. Buchcik, but it existed (in two places) as part of commit f06307e2 by Daniel Veillard.
This code appears to have been added back in commit 1566d3a9 by Daniel Veillard. (At that time type
was an int
parameter instead of an enum, though.)