summaryrefslogtreecommitdiff
path: root/absl/flags
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2022-06-14 12:58:49 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-06-14 12:59:46 -0700
commitcfd9476bffc36ebb14d09d17424c0878626b3bb9 (patch)
treef30920d8e3d81d93344f6115734d2536518bcb81 /absl/flags
parentbf93dba8e2058c64fc1140c9035bbf9bbe20bfdf (diff)
flags/marshalling_test: work around bogus GCC 12 -Wmaybe-uninitialized warning
PiperOrigin-RevId: 454934969 Change-Id: Ia4c157133e73ff16390179b37f7a789fc03fa92e
Diffstat (limited to 'absl/flags')
-rw-r--r--absl/flags/marshalling_test.cc34
1 files changed, 19 insertions, 15 deletions
diff --git a/absl/flags/marshalling_test.cc b/absl/flags/marshalling_test.cc
index 691cd2f1..7b6d2ad5 100644
--- a/absl/flags/marshalling_test.cc
+++ b/absl/flags/marshalling_test.cc
@@ -933,17 +933,17 @@ TEST(MarshallingTest, TestOptionalDoubleUnparsing) {
// --------------------------------------------------------------------
TEST(MarshallingTest, TestOptionalStringUnparsing) {
- absl::optional<std::string> value;
+ absl::optional<std::string> strvalue;
+ EXPECT_EQ(absl::UnparseFlag(strvalue), "");
- EXPECT_EQ(absl::UnparseFlag(value), "");
- value = "asdfg";
- EXPECT_EQ(absl::UnparseFlag(value), "asdfg");
- value = " ";
- EXPECT_EQ(absl::UnparseFlag(value), " ");
- value = ""; // This is UB to set optional string flag to ""
- EXPECT_EQ(absl::UnparseFlag(value), "");
- value = absl::nullopt;
- EXPECT_EQ(absl::UnparseFlag(value), "");
+ strvalue = "asdfg";
+ EXPECT_EQ(absl::UnparseFlag(strvalue), "asdfg");
+
+ strvalue = " ";
+ EXPECT_EQ(absl::UnparseFlag(strvalue), " ");
+
+ strvalue = ""; // It is UB to set an optional string flag to ""
+ EXPECT_EQ(absl::UnparseFlag(strvalue), "");
}
// --------------------------------------------------------------------
@@ -952,18 +952,22 @@ TEST(MarshallingTest, TestOptionalStringUnparsing) {
TEST(MarshallingTest, TestStdOptionalUnparsing) {
std::optional<std::string> strvalue;
-
EXPECT_EQ(absl::UnparseFlag(strvalue), "");
+
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), "");
- std::optional<int> intvalue(10);
+ std::optional<int> intvalue;
+ EXPECT_EQ(absl::UnparseFlag(intvalue), "");
+ intvalue = 10;
EXPECT_EQ(absl::UnparseFlag(intvalue), "10");
- intvalue = std::nullopt;
- EXPECT_EQ(absl::UnparseFlag(intvalue), "");
}
// --------------------------------------------------------------------