[gn] Fix Value::operator== for empty lists

The previous Copy-On-Write optimization for ValueList in
https://gn-review.googlesource.com/c/gn/+/21340 introduced a bug where
Value::operator== would return false if one list was unallocated
(list_ptr_ == nullptr) and the other was explicitly allocated but empty.

This commit removes the explicit nullptr check in operator==, allowing
empty lists to be compared properly via list_value(), and adds a unit
test to prevent regressions.

Bug: 484863025
Change-Id: I9c4bdd53fb22700ce389c9e3f8a3f12fd928c26d
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/21360
Commit-Queue: Takuto Ikuta <tikuta@google.com>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: David Turner <digit@google.com>
diff --git a/src/gn/value.cc b/src/gn/value.cc
index 43e2118..e2aa11a 100644
--- a/src/gn/value.cc
+++ b/src/gn/value.cc
@@ -273,8 +273,6 @@
     case Value::LIST:
       if (list_ptr_ == other.list_ptr_)
         return true;
-      if (!list_ptr_ || !other.list_ptr_)
-        return false;
       return list_value() == other.list_value();
     case Value::SCOPE:
       return scope_value()->CheckCurrentScopeValuesEqual(other.scope_value());
diff --git a/src/gn/value_unittest.cc b/src/gn/value_unittest.cc
index 555f101..520ee7d 100644
--- a/src/gn/value_unittest.cc
+++ b/src/gn/value_unittest.cc
@@ -58,3 +58,23 @@
   Value nested_scopeval(nullptr, std::unique_ptr<Scope>(nested_scope));
   EXPECT_FALSE(nested_scopeval == nested_scopeval);
 }
+
+TEST(Value, ListEquality) {
+  Value empty_list1(nullptr, Value::LIST);
+  Value empty_list2(nullptr, Value::LIST);
+  EXPECT_TRUE(empty_list1 == empty_list2);
+
+  // Trigger one to allocate its ValueList.
+  empty_list1.list_value();
+  EXPECT_TRUE(empty_list1 == empty_list2);
+  EXPECT_TRUE(empty_list2 == empty_list1);
+
+  // Trigger both to allocate.
+  empty_list2.list_value();
+  EXPECT_TRUE(empty_list1 == empty_list2);
+
+  // Add an item to one list.
+  empty_list1.list_value().push_back(Value(nullptr, "foo"));
+  EXPECT_FALSE(empty_list1 == empty_list2);
+  EXPECT_FALSE(empty_list2 == empty_list1);
+}