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

Fix some "enumeration values not explicitly handled in switch" warnings #555

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 56 additions & 58 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1970,59 +1970,60 @@ class basic_json
case value_t::object:
{
object = create<object_t>();
break;
return;
}

case value_t::array:
{
array = create<array_t>();
break;
return;
}

case value_t::string:
{
string = create<string_t>("");
break;
return;
}

case value_t::boolean:
{
boolean = boolean_t(false);
break;
return;
}

case value_t::number_integer:
{
number_integer = number_integer_t(0);
break;
return;
}

case value_t::number_unsigned:
{
number_unsigned = number_unsigned_t(0);
break;
return;
}

case value_t::number_float:
{
number_float = number_float_t(0.0);
break;
return;
}

case value_t::null:
{
break;
return;
}

default:
case value_t::discarded:
{
if (t == value_t::null)
{
JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 2.1.1")); // LCOV_EXCL_LINE
}
break;
return;
}
}
assert(false);
}

/// constructor for strings
Expand Down Expand Up @@ -2824,31 +2825,37 @@ class basic_json
AllocatorType<object_t> alloc;
alloc.destroy(m_value.object);
alloc.deallocate(m_value.object, 1);
break;
return;
}

case value_t::array:
{
AllocatorType<array_t> alloc;
alloc.destroy(m_value.array);
alloc.deallocate(m_value.array, 1);
break;
return;
}

case value_t::string:
{
AllocatorType<string_t> alloc;
alloc.destroy(m_value.string);
alloc.deallocate(m_value.string, 1);
break;
return;
}

default:
case value_t::null:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::discarded:
{
// all other types need no specific destructor
break;
return;
}
}
assert(false);
}

/// @}
Expand Down Expand Up @@ -9334,25 +9341,26 @@ class basic_json
*/
std::string type_name() const
{
switch (m_type)
{
switch (m_type)
{
case value_t::null:
return "null";
case value_t::object:
return "object";
case value_t::array:
return "array";
case value_t::string:
return "string";
case value_t::boolean:
return "boolean";
case value_t::discarded:
return "discarded";
default:
return "number";
}
case value_t::null:
return "null";
case value_t::object:
return "object";
case value_t::array:
return "array";
case value_t::string:
return "string";
case value_t::boolean:
return "boolean";
case value_t::discarded:
return "discarded";
case value_t::number_unsigned:
case value_t::number_integer:
case value_t::number_float:
return "number";
}
assert(false);
}


Expand Down Expand Up @@ -12091,37 +12099,27 @@ class basic_json
strtonum num_converter(reinterpret_cast<const char*>(m_start),
reinterpret_cast<const char*>(m_cursor));

switch (token)
if (token == lexer::token_type::value_unsigned)
{
case lexer::token_type::value_unsigned:
number_unsigned_t val;
if (num_converter.to(val))
{
number_unsigned_t val;
if (num_converter.to(val))
{
// parsing successful
result.m_type = value_t::number_unsigned;
result.m_value = val;
return true;
}
break;
}

case lexer::token_type::value_integer:
{
number_integer_t val;
if (num_converter.to(val))
{
// parsing successful
result.m_type = value_t::number_integer;
result.m_value = val;
return true;
}
break;
// parsing successful
result.m_type = value_t::number_unsigned;
result.m_value = val;
return true;
}
}

default:
if (token == lexer::token_type::value_integer)
{
number_integer_t val;
if (num_converter.to(val))
{
break;
// parsing successful
result.m_type = value_t::number_integer;
result.m_value = val;
return true;
}
}

Expand Down
Loading