Enable -Wshadow

Enable -Wshadow for upstream pigweed to improve compatibility with
projects that decide to enable this flag.

Change-Id: I7e1ce22f245e719ec78118370e591437abe07f0a
diff --git a/BUILDCONFIG.gn b/BUILDCONFIG.gn
index 0bcc9a4..20ce345 100644
--- a/BUILDCONFIG.gn
+++ b/BUILDCONFIG.gn
@@ -69,7 +69,13 @@
     }
 
     # Add default configs to use for all binary build targets.
-    configs += [ "$dir_pw_build:default" ]
+    configs += [
+      "$dir_pw_build:default",
+
+      # This is not recommended for projects, and is only enabled for upstream
+      # Pigweed to improve compatibility with projects that use these warnings.
+      "$dir_pw_build:extra_strict_warnings",
+    ]
   }
 }
 
diff --git a/pw_build/BUILD.gn b/pw_build/BUILD.gn
index 343a14c..38afdf8 100644
--- a/pw_build/BUILD.gn
+++ b/pw_build/BUILD.gn
@@ -52,6 +52,13 @@
   cflags_cc = [ "-Wnon-virtual-dtor" ]
 }
 
+# This config contains warnings that we don't necessarily recommend projects
+# enable, but are enabled for upstream Pigweed for maximum project
+# compatibility.
+config("extra_strict_warnings") {
+  cflags = [ "-Wshadow" ]
+}
+
 config("cpp11") {
   cflags_cc = [ "-std=c++11" ]
 }
diff --git a/pw_containers/vector_test.cc b/pw_containers/vector_test.cc
index 4d584d1..24f42ab 100644
--- a/pw_containers/vector_test.cc
+++ b/pw_containers/vector_test.cc
@@ -28,7 +28,7 @@
               alignof(Vector<std::max_align_t, 1>));
 
 struct CopyOnly {
-  explicit CopyOnly(int value) : value(value) {}
+  explicit CopyOnly(int val) : value(val) {}
 
   CopyOnly(const CopyOnly& other) { value = other.value; }
 
@@ -43,7 +43,7 @@
 };
 
 struct MoveOnly {
-  explicit MoveOnly(int value) : value(value) {}
+  explicit MoveOnly(int val) : value(val) {}
 
   MoveOnly(const MoveOnly&) = delete;
 
diff --git a/pw_kvs/entry_test.cc b/pw_kvs/entry_test.cc
index 53e9740..e4512de 100644
--- a/pw_kvs/entry_test.cc
+++ b/pw_kvs/entry_test.cc
@@ -98,8 +98,9 @@
 constexpr auto kEntry1 = AsBytes(kEntryWithoutPadding1, kPadding1);
 static_assert(kEntry1.size() == 32);
 
-ChecksumCrc16 checksum;
-constexpr EntryFormat kFormatWithChecksum{kMagicWithChecksum, &checksum};
+ChecksumCrc16 default_checksum;
+constexpr EntryFormat kFormatWithChecksum{kMagicWithChecksum,
+                                          &default_checksum};
 constexpr internal::EntryFormats kFormats(kFormatWithChecksum);
 
 class ValidEntryInFlash : public ::testing::Test {
diff --git a/pw_kvs/key_value_store.cc b/pw_kvs/key_value_store.cc
index f3cb4a6..325ca16 100644
--- a/pw_kvs/key_value_store.cc
+++ b/pw_kvs/key_value_store.cc
@@ -1226,10 +1226,10 @@
   DBG("  Max entry count = %zu", entry_cache_.max_entries());
   DBG(" ");
   DBG("      #     hash        version    address   address (hex)");
-  size_t i = 0;
+  size_t count = 0;
   for (const EntryMetadata& metadata : entry_cache_) {
     DBG("   |%3zu: | %8zx  |%8zu  | %8zu | %8zx",
-        i++,
+        count++,
         size_t(metadata.hash()),
         size_t(metadata.transaction_id()),
         size_t(metadata.first_address()),
diff --git a/pw_kvs/key_value_store_binary_format_test.cc b/pw_kvs/key_value_store_binary_format_test.cc
index fe1fdb5..97f0922 100644
--- a/pw_kvs/key_value_store_binary_format_test.cc
+++ b/pw_kvs/key_value_store_binary_format_test.cc
@@ -57,7 +57,7 @@
   State (&algorithm_)(span<const byte>, State);
 };
 
-ChecksumFunction<uint32_t> checksum(SimpleChecksum);
+ChecksumFunction<uint32_t> default_checksum(SimpleChecksum);
 
 // Returns a buffer containing the necessary padding for an entry.
 template <size_t kAlignmentBytes, size_t kKeyLength, size_t kValueSize = 0>
@@ -163,7 +163,7 @@
       : flash_(internal::Entry::kMinAlignmentBytes),
         partition_(&flash_),
         kvs_(&partition_,
-             {.magic = kMagic, .checksum = &checksum},
+             {.magic = kMagic, .checksum = &default_checksum},
              kNoGcOptions) {}
 
   void InitFlashTo(span<const byte> contents) {
@@ -370,7 +370,7 @@
       : flash_(internal::Entry::kMinAlignmentBytes),
         partition_(&flash_),
         kvs_(&partition_,
-             {.magic = kMagic, .checksum = &checksum},
+             {.magic = kMagic, .checksum = &default_checksum},
              kRecoveryNoGcOptions) {}
 
   void InitFlashTo(span<const byte> contents) {
@@ -622,7 +622,7 @@
         partition_(&flash_),
         kvs_(&partition_,
              {{
-                 {.magic = kMagic, .checksum = &checksum},
+                 {.magic = kMagic, .checksum = &default_checksum},
                  {.magic = kAltMagic, .checksum = &alt_checksum},
                  {.magic = kNoChecksumMagic, .checksum = nullptr},
              }},
@@ -833,7 +833,9 @@
   ASSERT_EQ(Status::OK, kvs_.FullMaintenance());
 
   KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors, 2, 1> local_kvs(
-      &partition_, {.magic = kMagic, .checksum = &checksum}, kNoGcOptions);
+      &partition_,
+      {.magic = kMagic, .checksum = &default_checksum},
+      kNoGcOptions);
 
   ASSERT_EQ(Status::OK, local_kvs.Init());
   EXPECT_EQ(false, local_kvs.error_detected());
@@ -854,7 +856,7 @@
         partition_(&flash_),
         kvs_(&partition_,
              {{
-                 {.magic = kMagic, .checksum = &checksum},
+                 {.magic = kMagic, .checksum = &default_checksum},
                  {.magic = kAltMagic, .checksum = &alt_checksum},
                  {.magic = kNoChecksumMagic, .checksum = nullptr},
              }},
@@ -888,7 +890,9 @@
   ASSERT_EQ(Status::OK, kvs_.FullMaintenance());
 
   KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors, 1, 1> local_kvs(
-      &partition_, {.magic = kMagic, .checksum = &checksum}, kNoGcOptions);
+      &partition_,
+      {.magic = kMagic, .checksum = &default_checksum},
+      kNoGcOptions);
 
   ASSERT_EQ(Status::OK, local_kvs.Init());
   EXPECT_EQ(false, local_kvs.error_detected());
@@ -908,7 +912,7 @@
       : flash_(internal::Entry::kMinAlignmentBytes),
         partition_(&flash_),
         kvs_(&partition_,
-             {.magic = kMagic, .checksum = &checksum},
+             {.magic = kMagic, .checksum = &default_checksum},
              kRecoveryLazyGcOptions) {
     partition_.Erase();
     std::memcpy(flash_.buffer().data(),
@@ -1000,7 +1004,7 @@
       : flash_(internal::Entry::kMinAlignmentBytes),
         partition_(&flash_),
         kvs_(&partition_,
-             {.magic = kMagic, .checksum = &checksum},
+             {.magic = kMagic, .checksum = &default_checksum},
              kRecoveryLazyGcOptions) {
     partition_.Erase();
     std::memcpy(flash_.buffer().data(),
@@ -1056,7 +1060,7 @@
   // two sectors.
   KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors, 2> local_kvs(
       &partition_,
-      {.magic = kMagic, .checksum = &checksum},
+      {.magic = kMagic, .checksum = &default_checksum},
       kRecoveryLazyGcOptions);
   ASSERT_EQ(Status::OK, local_kvs.Init());
 
diff --git a/pw_kvs/key_value_store_test.cc b/pw_kvs/key_value_store_test.cc
index 32716a9..c6c3b0a 100644
--- a/pw_kvs/key_value_store_test.cc
+++ b/pw_kvs/key_value_store_test.cc
@@ -171,7 +171,8 @@
 constexpr std::array<const char*, 3> keys{"TestKey1", "Key2", "TestKey3"};
 
 ChecksumCrc16 checksum;
-constexpr EntryFormat format{.magic = 0xBAD'C0D3, .checksum = &checksum};
+constexpr EntryFormat default_format{.magic = 0xBAD'C0D3,
+                                     .checksum = &checksum};
 
 size_t RoundUpForAlignment(size_t size) {
   return AlignUp(size, test_partition.alignment_bytes());
@@ -204,7 +205,7 @@
 
 class EmptyInitializedKvs : public ::testing::Test {
  protected:
-  EmptyInitializedKvs() : kvs_(&test_partition, format) {
+  EmptyInitializedKvs() : kvs_(&test_partition, default_format) {
     test_partition.Erase();
     ASSERT_EQ(Status::OK, kvs_.Init());
   }
@@ -406,7 +407,7 @@
 
   // Ensure that the re-added key is still present after reinitialization.
   KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors> new_kvs(&test_partition,
-                                                              format);
+                                                              default_format);
   ASSERT_EQ(Status::OK, new_kvs.Init());
 
   EXPECT_EQ(Status::OK, new_kvs.Put("kEy", as_bytes(span("45678"))));
@@ -480,9 +481,9 @@
   for (KeyValueStore::Item entry : kvs_) {
     EXPECT_STREQ(entry.key(), "kEy");  // Make sure null-terminated.
 
-    char buffer[sizeof("123")] = {};
-    EXPECT_EQ(Status::OK, entry.Get(&buffer));
-    EXPECT_STREQ("123", buffer);
+    char temp[sizeof("123")] = {};
+    EXPECT_EQ(Status::OK, entry.Get(&temp));
+    EXPECT_STREQ("123", temp);
   }
 }
 
@@ -490,11 +491,11 @@
   ASSERT_EQ(Status::OK, kvs_.Put("key", as_bytes(span("not bad!"))));
 
   for (KeyValueStore::Item entry : kvs_) {
-    char buffer[5];
-    auto result = entry.Get(as_writable_bytes(span(buffer)), 4);
+    char temp[5];
+    auto result = entry.Get(as_writable_bytes(span(temp)), 4);
     EXPECT_EQ(Status::OK, result.status());
     EXPECT_EQ(5u, result.size());
-    EXPECT_STREQ("bad!", buffer);
+    EXPECT_STREQ("bad!", temp);
   }
 }
 
@@ -859,7 +860,7 @@
   // Enable different KVS which should be able to properly setup the same map
   // from what is stored in flash.
   static KeyValueStoreBuffer<kMaxEntries, kMaxUsableSectors> kvs_local(
-      &test_partition, format);
+      &test_partition, default_format);
   ASSERT_EQ(Status::OK, kvs_local.Init());
   EXPECT_EQ(kvs_local.size(), keys.size());
 
@@ -1244,7 +1245,7 @@
 
 class LargeEmptyInitializedKvs : public ::testing::Test {
  protected:
-  LargeEmptyInitializedKvs() : kvs_(&large_test_partition, format) {
+  LargeEmptyInitializedKvs() : kvs_(&large_test_partition, default_format) {
     ASSERT_EQ(
         Status::OK,
         large_test_partition.Erase(0, large_test_partition.sector_count()));
diff --git a/pw_minimal_cpp_stdlib/test.cc b/pw_minimal_cpp_stdlib/test.cc
index b0a1ecd..c0badd1 100644
--- a/pw_minimal_cpp_stdlib/test.cc
+++ b/pw_minimal_cpp_stdlib/test.cc
@@ -245,7 +245,7 @@
 }
 
 struct MoveTester {
-  MoveTester(int magic_value) : magic_value(magic_value), moved(false) {}
+  MoveTester(int value) : magic_value(value), moved(false) {}
 
   MoveTester(const MoveTester&) = default;
 
diff --git a/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc b/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc
index f4dd005..db5c14c 100644
--- a/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc
+++ b/pw_ring_buffer/prefixed_entry_ring_buffer_test.cc
@@ -290,8 +290,8 @@
   EXPECT_EQ(ring.SetBuffer(test_buffer), Status::OK);
 
   // Entry data is entry size - preamble (single byte in this case).
-  byte single_entry_data[kEntrySizeBytes - 1u];
-  auto entry_data = span(single_entry_data);
+  byte single_entry_buffer[kEntrySizeBytes - 1u];
+  auto entry_data = span(single_entry_buffer);
   size_t i;
 
   size_t loop_goal = preload ? 500 : 1;
@@ -302,8 +302,8 @@
       // Prime the ringbuffer with some junk data to get the buffer
       // wrapped.
       for (i = 0; i < (kTotalEntryCount * (main_loop_count % 64u)); i++) {
-        memset(single_entry_data, i, sizeof(single_entry_data));
-        ring.PushBack(single_entry_data);
+        memset(single_entry_buffer, i, sizeof(single_entry_buffer));
+        ring.PushBack(single_entry_buffer);
       }
     }
 
@@ -311,17 +311,17 @@
     pw::Vector<byte, kTestBufferSize> expected_result;
     for (i = 0; i < kTotalEntryCount; i++) {
       // First component of the entry: the varint size.
-      static_assert(sizeof(single_entry_data) < 127);
-      expected_result.push_back(byte(sizeof(single_entry_data)));
+      static_assert(sizeof(single_entry_buffer) < 127);
+      expected_result.push_back(byte(sizeof(single_entry_buffer)));
 
       // Second component of the entry: the raw data.
-      memset(single_entry_data, 'a' + i, sizeof(single_entry_data));
+      memset(single_entry_buffer, 'a' + i, sizeof(single_entry_buffer));
       for (byte b : entry_data) {
         expected_result.push_back(b);
       }
 
       // The ring buffer internally pushes the varint size byte.
-      ring.PushBack(single_entry_data);
+      ring.PushBack(single_entry_buffer);
     }
 
     // Check values before doing the dering.
diff --git a/pw_tokenizer/base64_test.cc b/pw_tokenizer/base64_test.cc
index 4cf6b18..8a6f8b6 100644
--- a/pw_tokenizer/base64_test.cc
+++ b/pw_tokenizer/base64_test.cc
@@ -33,8 +33,8 @@
 
 const struct TestData {
   template <size_t kSize>
-  TestData(const char (&binary)[kSize], const char* base64)
-      : binary{as_bytes(span(binary, kSize - 1))}, base64(base64) {}
+  TestData(const char (&binary_data)[kSize], const char* base64_data)
+      : binary{as_bytes(span(binary_data, kSize - 1))}, base64(base64_data) {}
 
   span<const std::byte> binary;
   std::string_view base64;
diff --git a/pw_unit_test/public/pw_unit_test/framework.h b/pw_unit_test/public/pw_unit_test/framework.h
index 6115a00..7462f1a 100644
--- a/pw_unit_test/public/pw_unit_test/framework.h
+++ b/pw_unit_test/public/pw_unit_test/framework.h
@@ -289,12 +289,12 @@
   TestInfo(const char* const test_suite_name,
            const char* const test_name,
            const char* const file_name,
-           void (*run)(const TestInfo&))
+           void (*run_func)(const TestInfo&))
       : test_case_{
         .suite_name = test_suite_name,
         .test_name = test_name,
         .file_name = file_name,
-       }, run_(run) {
+       }, run_(run_func) {
     Framework::Get().RegisterTest(this);
   }