0
0
mirror of https://github.com/zeux/pugixml.git synced 2025-01-14 01:47:55 +08:00

XPath: Remove the use of fallthrough switch cases

We were previously relying on non-standard comment detection that is
supported by gcc/clang to avoid warnings about implicit fallthrough.

This can be solved using attributes but using them requires a lot of
compiler-specific detection logic because not all versions of gcc/clang
support them.

We don't *really* need to rely on fallthrough here - the type conversion
block can be located *after* the AST type switch instead, which means
that any AST type that has type ambiguity can fall back to that in the
future.

Fixes #331.
This commit is contained in:
Arseny Kapoulkine 2020-02-19 07:32:53 -08:00
parent 6fbe927575
commit 76c3914484

View File

@ -10415,12 +10415,15 @@ PUGI__NS_BEGIN
if (_rettype == xpath_type_boolean)
return _data.variable->get_boolean();
// variable needs to be converted to the correct type, this is handled by the default statement below
// variable needs to be converted to the correct type, this is handled by the fallthrough block below
break;
}
// fallthrough
default:
{
;
}
// none of the ast types that return the value directly matched, we need to perform type conversion
switch (_rettype)
{
case xpath_type_number:
@ -10445,8 +10448,6 @@ PUGI__NS_BEGIN
return false;
}
}
}
}
double eval_number(const xpath_context& c, const xpath_stack& stack)
{
@ -10552,12 +10553,15 @@ PUGI__NS_BEGIN
if (_rettype == xpath_type_number)
return _data.variable->get_number();
// variable needs to be converted to the correct type, this is handled by the default statement below
// variable needs to be converted to the correct type, this is handled by the fallthrough block below
break;
}
// fallthrough
default:
{
;
}
// none of the ast types that return the value directly matched, we need to perform type conversion
switch (_rettype)
{
case xpath_type_boolean:
@ -10581,9 +10585,6 @@ PUGI__NS_BEGIN
assert(false && "Wrong expression for return type number"); // unreachable
return 0;
}
}
}
}
xpath_string eval_string_concat(const xpath_context& c, const xpath_stack& stack)
@ -10838,12 +10839,15 @@ PUGI__NS_BEGIN
if (_rettype == xpath_type_string)
return xpath_string::from_const(_data.variable->get_string());
// variable needs to be converted to the correct type, this is handled by the default statement below
// variable needs to be converted to the correct type, this is handled by the fallthrough block below
break;
}
// fallthrough
default:
{
;
}
// none of the ast types that return the value directly matched, we need to perform type conversion
switch (_rettype)
{
case xpath_type_boolean:
@ -10867,8 +10871,6 @@ PUGI__NS_BEGIN
return xpath_string();
}
}
}
}
xpath_node_set_raw eval_node_set(const xpath_context& c, const xpath_stack& stack, nodeset_eval_t eval)
{
@ -10989,15 +10991,18 @@ PUGI__NS_BEGIN
return ns;
}
// variable needs to be converted to the correct type, this is handled by the default statement below
// variable needs to be converted to the correct type, this is handled by the fallthrough block below
break;
}
// fallthrough
default:
;
}
// none of the ast types that return the value directly matched, but conversions to node set are invalid
assert(false && "Wrong expression for return type node set"); // unreachable
return xpath_node_set_raw();
}
}
void optimize(xpath_allocator* alloc)
{