flags/marshalling_test: work around bogus GCC 12 -Wmaybe-uninitialized warning

PiperOrigin-RevId: 454934969
Change-Id: Ia4c157133e73ff16390179b37f7a789fc03fa92e
pull/1200/head
Derek Mauro 3 years ago committed by Copybara-Service
parent bf93dba8e2
commit cfd9476bff
  1. 34
      absl/flags/marshalling_test.cc

@ -933,17 +933,17 @@ TEST(MarshallingTest, TestOptionalDoubleUnparsing) {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
TEST(MarshallingTest, TestOptionalStringUnparsing) { TEST(MarshallingTest, TestOptionalStringUnparsing) {
absl::optional<std::string> value; absl::optional<std::string> strvalue;
EXPECT_EQ(absl::UnparseFlag(strvalue), "");
EXPECT_EQ(absl::UnparseFlag(value), ""); strvalue = "asdfg";
value = "asdfg"; EXPECT_EQ(absl::UnparseFlag(strvalue), "asdfg");
EXPECT_EQ(absl::UnparseFlag(value), "asdfg");
value = " "; strvalue = " ";
EXPECT_EQ(absl::UnparseFlag(value), " "); EXPECT_EQ(absl::UnparseFlag(strvalue), " ");
value = ""; // This is UB to set optional string flag to ""
EXPECT_EQ(absl::UnparseFlag(value), ""); strvalue = ""; // It is UB to set an optional string flag to ""
value = absl::nullopt; EXPECT_EQ(absl::UnparseFlag(strvalue), "");
EXPECT_EQ(absl::UnparseFlag(value), "");
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -952,18 +952,22 @@ TEST(MarshallingTest, TestOptionalStringUnparsing) {
TEST(MarshallingTest, TestStdOptionalUnparsing) { TEST(MarshallingTest, TestStdOptionalUnparsing) {
std::optional<std::string> strvalue; std::optional<std::string> strvalue;
EXPECT_EQ(absl::UnparseFlag(strvalue), ""); EXPECT_EQ(absl::UnparseFlag(strvalue), "");
strvalue = "asdfg"; strvalue = "asdfg";
EXPECT_EQ(absl::UnparseFlag(strvalue), "asdfg"); EXPECT_EQ(absl::UnparseFlag(strvalue), "asdfg");
strvalue = std::nullopt;
strvalue = " ";
EXPECT_EQ(absl::UnparseFlag(strvalue), " ");
strvalue = ""; // It is UB to set an optional string flag to ""
EXPECT_EQ(absl::UnparseFlag(strvalue), ""); EXPECT_EQ(absl::UnparseFlag(strvalue), "");
std::optional<int> intvalue(10); std::optional<int> intvalue;
EXPECT_EQ(absl::UnparseFlag(intvalue), "");
intvalue = 10;
EXPECT_EQ(absl::UnparseFlag(intvalue), "10"); EXPECT_EQ(absl::UnparseFlag(intvalue), "10");
intvalue = std::nullopt;
EXPECT_EQ(absl::UnparseFlag(intvalue), "");
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

Loading…
Cancel
Save