From ad24d9485db9d9af7b2b3210c7601872fc1a6ba5 Mon Sep 17 00:00:00 2001 From: Crzyrndm Date: Wed, 11 Jul 2018 12:27:18 +1200 Subject: [PATCH] Resolve CI warning about using an uninitialised variable --- include/xlnt/utils/optional.hpp | 6 +++ source/detail/serialization/xlsx_consumer.cpp | 42 ++++++++++--------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/include/xlnt/utils/optional.hpp b/include/xlnt/utils/optional.hpp index bc02407d..e019f316 100644 --- a/include/xlnt/utils/optional.hpp +++ b/include/xlnt/utils/optional.hpp @@ -170,6 +170,8 @@ public: /// 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_) { value_ref() = value; @@ -179,6 +181,7 @@ public: new (&storage_) T(value); has_value_ = true; } +#pragma GCC diagnostic pop } /// @@ -190,6 +193,8 @@ public: // 1. have to deal with implicit conversions internally with perfect forwarding // 2. have to deal with the noexcept specfiers for all the different variations // overload is just far and away the simpler solution +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" if (has_value_) { value_ref() = std::move(value); @@ -199,6 +204,7 @@ public: new (&storage_) T(std::move(value)); has_value_ = true; } +#pragma GCC diagnostic pop } /// diff --git a/source/detail/serialization/xlsx_consumer.cpp b/source/detail/serialization/xlsx_consumer.cpp index 336ddaa3..a634bf7b 100644 --- a/source/detail/serialization/xlsx_consumer.cpp +++ b/source/detail/serialization/xlsx_consumer.cpp @@ -387,7 +387,7 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id) props.sync_horizontal.set(parser().attribute("syncHorizontal")); } if (parser().attribute_present("syncVertical")) - {// optional, boolean, false + { // optional, boolean, false props.sync_vertical.set(parser().attribute("syncVertical")); } 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("transitionEvaluation")); } if (parser().attribute_present("transitionEntry")) - {// optional, boolean, false + { // optional, boolean, false props.transition_entry.set(parser().attribute("transitionEntry")); } if (parser().attribute_present("published")) - {// optional, boolean, true + { // optional, boolean, true props.published.set(parser().attribute("published")); } 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("codeName")); } if (parser().attribute_present("filterMode")) - {// optional, boolean, false + { // optional, boolean, false props.filter_mode.set(parser().attribute("filterMode")); } if (parser().attribute_present("enableFormatConditionsCalculation")) - {// optional, boolean, true + { // optional, boolean, true props.enable_format_condition_calculation.set(parser().attribute("enableFormatConditionsCalculation")); } 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(std::stoull(parser().attribute("min"))); auto max = static_cast(std::stoull(parser().attribute("max"))); - optional width; - - if (parser().attribute_present("width")) - { - width = (parser().attribute("width") * 7 - 5) / 7; - } - - optional column_style; - - if (parser().attribute_present("style")) - { - column_style = parser().attribute("style"); - } + // avoid uninitialised warnings in GCC by using a lambda to make the conditional initialisation + optional width = [](xml::parser &p) -> xlnt::optional { + if (p.attribute_present("width")) + { + return (p.attribute("width") * 7 - 5) / 7; + } + return xlnt::optional(); + }(parser()); + // avoid uninitialised warnings in GCC by using a lambda to make the conditional initialisation + optional column_style = [](xml::parser &p) -> xlnt::optional { + if (p.attribute_present("style")) + { + return p.attribute("style"); + } + return xlnt::optional(); + }(parser()); auto custom = parser().attribute_present("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(), [&](const std::pair &p) { return p.second == worksheet_rel.id(); - })->first; + }) + ->first; auto id = sheet_title_id_map_[title]; auto index = sheet_title_index_map_[title];