Resolve CI warning about using an uninitialised variable

This commit is contained in:
Crzyrndm 2018-07-11 12:27:18 +12:00
parent b004d0863c
commit ad24d9485d
2 changed files with 29 additions and 19 deletions

View File

@ -170,6 +170,8 @@ public:
/// </summary> /// </summary>
void set(const T &value) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(set_copy_noexcept_t{})) void set(const T &value) noexcept(XLNT_NOEXCEPT_VALUE_COMPAT(set_copy_noexcept_t{}))
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
if (has_value_) if (has_value_)
{ {
value_ref() = value; value_ref() = value;
@ -179,6 +181,7 @@ public:
new (&storage_) T(value); new (&storage_) T(value);
has_value_ = true; has_value_ = true;
} }
#pragma GCC diagnostic pop
} }
/// <summary> /// <summary>
@ -190,6 +193,8 @@ public:
// 1. have to deal with implicit conversions internally with perfect forwarding // 1. have to deal with implicit conversions internally with perfect forwarding
// 2. have to deal with the noexcept specfiers for all the different variations // 2. have to deal with the noexcept specfiers for all the different variations
// overload is just far and away the simpler solution // overload is just far and away the simpler solution
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
if (has_value_) if (has_value_)
{ {
value_ref() = std::move(value); value_ref() = std::move(value);
@ -199,6 +204,7 @@ public:
new (&storage_) T(std::move(value)); new (&storage_) T(std::move(value));
has_value_ = true; has_value_ = true;
} }
#pragma GCC diagnostic pop
} }
/// <summary> /// <summary>

View File

@ -387,7 +387,7 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
props.sync_horizontal.set(parser().attribute<bool>("syncHorizontal")); props.sync_horizontal.set(parser().attribute<bool>("syncHorizontal"));
} }
if (parser().attribute_present("syncVertical")) if (parser().attribute_present("syncVertical"))
{// optional, boolean, false { // optional, boolean, false
props.sync_vertical.set(parser().attribute<bool>("syncVertical")); props.sync_vertical.set(parser().attribute<bool>("syncVertical"));
} }
if (parser().attribute_present("syncRef")) if (parser().attribute_present("syncRef"))
@ -399,11 +399,11 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
props.transition_evaluation.set(parser().attribute<bool>("transitionEvaluation")); props.transition_evaluation.set(parser().attribute<bool>("transitionEvaluation"));
} }
if (parser().attribute_present("transitionEntry")) if (parser().attribute_present("transitionEntry"))
{// optional, boolean, false { // optional, boolean, false
props.transition_entry.set(parser().attribute<bool>("transitionEntry")); props.transition_entry.set(parser().attribute<bool>("transitionEntry"));
} }
if (parser().attribute_present("published")) if (parser().attribute_present("published"))
{// optional, boolean, true { // optional, boolean, true
props.published.set(parser().attribute<bool>("published")); props.published.set(parser().attribute<bool>("published"));
} }
if (parser().attribute_present("codeName")) if (parser().attribute_present("codeName"))
@ -411,11 +411,11 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
props.code_name.set(parser().attribute<std::string>("codeName")); props.code_name.set(parser().attribute<std::string>("codeName"));
} }
if (parser().attribute_present("filterMode")) if (parser().attribute_present("filterMode"))
{// optional, boolean, false { // optional, boolean, false
props.filter_mode.set(parser().attribute<bool>("filterMode")); props.filter_mode.set(parser().attribute<bool>("filterMode"));
} }
if (parser().attribute_present("enableFormatConditionsCalculation")) if (parser().attribute_present("enableFormatConditionsCalculation"))
{// optional, boolean, true { // optional, boolean, true
props.enable_format_condition_calculation.set(parser().attribute<bool>("enableFormatConditionsCalculation")); props.enable_format_condition_calculation.set(parser().attribute<bool>("enableFormatConditionsCalculation"));
} }
ws.d_->sheet_properties_.set(props); ws.d_->sheet_properties_.set(props);
@ -606,19 +606,22 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
auto min = static_cast<column_t::index_t>(std::stoull(parser().attribute("min"))); auto min = static_cast<column_t::index_t>(std::stoull(parser().attribute("min")));
auto max = static_cast<column_t::index_t>(std::stoull(parser().attribute("max"))); auto max = static_cast<column_t::index_t>(std::stoull(parser().attribute("max")));
optional<double> width; // avoid uninitialised warnings in GCC by using a lambda to make the conditional initialisation
optional<double> width = [](xml::parser &p) -> xlnt::optional<double> {
if (parser().attribute_present("width")) if (p.attribute_present("width"))
{ {
width = (parser().attribute<double>("width") * 7 - 5) / 7; return (p.attribute<double>("width") * 7 - 5) / 7;
} }
return xlnt::optional<double>();
optional<std::size_t> column_style; }(parser());
// avoid uninitialised warnings in GCC by using a lambda to make the conditional initialisation
if (parser().attribute_present("style")) optional<std::size_t> column_style = [](xml::parser &p) -> xlnt::optional<std::size_t> {
{ if (p.attribute_present("style"))
column_style = parser().attribute<std::size_t>("style"); {
} return p.attribute<std::size_t>("style");
}
return xlnt::optional<std::size_t>();
}(parser());
auto custom = parser().attribute_present("customWidth") auto custom = parser().attribute_present("customWidth")
? is_true(parser().attribute("customWidth")) ? is_true(parser().attribute("customWidth"))
@ -1843,7 +1846,8 @@ void xlsx_consumer::read_office_document(const std::string &content_type) // CT_
target_.d_->sheet_title_rel_id_map_.end(), target_.d_->sheet_title_rel_id_map_.end(),
[&](const std::pair<std::string, std::string> &p) { [&](const std::pair<std::string, std::string> &p) {
return p.second == worksheet_rel.id(); return p.second == worksheet_rel.id();
})->first; })
->first;
auto id = sheet_title_id_map_[title]; auto id = sheet_title_id_map_[title];
auto index = sheet_title_index_map_[title]; auto index = sheet_title_index_map_[title];