Fix ODR violations in quic_versions.h

gfe-relnote: n/a (no functional change)
PiperOrigin-RevId: 293541130
Change-Id: I8e1ae9a4ea316f40599ebfb17110fabfbcd2e128
diff --git a/quic/core/crypto/crypto_utils.cc b/quic/core/crypto/crypto_utils.cc
index 7de442b..bb346b5 100644
--- a/quic/core/crypto/crypto_utils.cc
+++ b/quic/core/crypto/crypto_utils.cc
@@ -135,7 +135,7 @@
 
 const uint8_t* InitialSaltForVersion(const ParsedQuicVersion& version,
                                      size_t* out_len) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync with initial encryption salts");
   switch (version.handshake_protocol) {
     case PROTOCOL_QUIC_CRYPTO:
diff --git a/quic/core/quic_dispatcher_test.cc b/quic/core/quic_dispatcher_test.cc
index 44e2bb7..8e7e278 100644
--- a/quic/core/quic_dispatcher_test.cc
+++ b/quic/core/quic_dispatcher_test.cc
@@ -940,7 +940,7 @@
 }
 
 TEST_F(QuicDispatcherTest, RejectDeprecatedVersionsWithVersionNegotiation) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Please add deprecated versions to this test");
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
   CreateTimeWaitListManager();
diff --git a/quic/core/quic_version_manager.cc b/quic/core/quic_version_manager.cc
index 35a71ae..408149e 100644
--- a/quic/core/quic_version_manager.cc
+++ b/quic/core/quic_version_manager.cc
@@ -23,7 +23,7 @@
       disable_version_q046_(GetQuicReloadableFlag(quic_disable_version_q046)),
       disable_version_q043_(GetQuicReloadableFlag(quic_disable_version_q043)),
       allowed_supported_versions_(std::move(supported_versions)) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync");
   RefilterSupportedVersions();
 }
@@ -42,7 +42,7 @@
 }
 
 void QuicVersionManager::MaybeRefilterSupportedVersions() {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync");
   if (enable_version_t099_ != GetQuicReloadableFlag(quic_enable_version_t099) ||
       disable_version_q050_ !=
diff --git a/quic/core/quic_version_manager_test.cc b/quic/core/quic_version_manager_test.cc
index 76d74fc..90179ba 100644
--- a/quic/core/quic_version_manager_test.cc
+++ b/quic/core/quic_version_manager_test.cc
@@ -16,7 +16,7 @@
 class QuicVersionManagerTest : public QuicTest {};
 
 TEST_F(QuicVersionManagerTest, QuicVersionManager) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedVersions().size() == 7u,
                 "Supported versions out of sync");
   SetQuicReloadableFlag(quic_enable_version_t099, false);
   SetQuicReloadableFlag(quic_enable_version_t050, false);
diff --git a/quic/core/quic_versions.cc b/quic/core/quic_versions.cc
index e92f048..33c5596 100644
--- a/quic/core/quic_versions.cc
+++ b/quic/core/quic_versions.cc
@@ -181,7 +181,7 @@
                << parsed_version.handshake_protocol;
       return 0;
   }
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync");
   switch (parsed_version.transport_version) {
     case QUIC_VERSION_43:
@@ -262,16 +262,16 @@
 }
 
 QuicTransportVersionVector AllSupportedTransportVersions() {
-  QuicTransportVersionVector supported_versions;
-  for (QuicTransportVersion version : kSupportedTransportVersions) {
-    supported_versions.push_back(version);
-  }
+  constexpr auto supported_transport_versions = SupportedTransportVersions();
+  QuicTransportVersionVector supported_versions(
+      supported_transport_versions.begin(), supported_transport_versions.end());
   return supported_versions;
 }
 
 ParsedQuicVersionVector AllSupportedVersions() {
-  return ParsedQuicVersionVector(kSupportedVersions.begin(),
-                                 kSupportedVersions.end());
+  constexpr auto supported_versions = SupportedVersions();
+  return ParsedQuicVersionVector(supported_versions.begin(),
+                                 supported_versions.end());
 }
 
 ParsedQuicVersionVector CurrentSupportedVersions() {
@@ -401,7 +401,7 @@
     return #x
 
 std::string QuicVersionToString(QuicTransportVersion transport_version) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync");
   switch (transport_version) {
     RETURN_STRING_LITERAL(QUIC_VERSION_43);
@@ -525,7 +525,7 @@
 }
 
 void QuicEnableVersion(ParsedQuicVersion parsed_version) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync");
   if (parsed_version.transport_version == QUIC_VERSION_99) {
     if (parsed_version.handshake_protocol == PROTOCOL_TLS1_3) {
diff --git a/quic/core/quic_versions.h b/quic/core/quic_versions.h
index 6e514f0..1f3738e 100644
--- a/quic/core/quic_versions.h
+++ b/quic/core/quic_versions.h
@@ -124,7 +124,7 @@
     QuicTransportVersion transport_version);
 
 // IETF draft version most closely approximated by TLS + v99.
-static const int kQuicIetfDraftVersion = 25;
+enum : int { kQuicIetfDraftVersion = 25 };
 
 // The crypto handshake protocols that can be used with QUIC.
 enum HandshakeProtocol {
@@ -313,26 +313,31 @@
 // skipped as necessary).
 //
 // See go/new-quic-version for more details on how to roll out new versions.
-static const QuicTransportVersion kSupportedTransportVersions[] = {
-    QUIC_VERSION_99, QUIC_VERSION_50, QUIC_VERSION_49,
-    QUIC_VERSION_48, QUIC_VERSION_46, QUIC_VERSION_43,
-};
+constexpr std::array<QuicTransportVersion, 6> SupportedTransportVersions() {
+  return std::array<QuicTransportVersion, 6>(
+      {QUIC_VERSION_99, QUIC_VERSION_50, QUIC_VERSION_49, QUIC_VERSION_48,
+       QUIC_VERSION_46, QUIC_VERSION_43});
+}
 
 // This vector contains all crypto handshake protocols that are supported.
-static const HandshakeProtocol kSupportedHandshakeProtocols[] = {
-    PROTOCOL_QUIC_CRYPTO, PROTOCOL_TLS1_3};
+constexpr std::array<HandshakeProtocol, 2> SupportedHandshakeProtocols() {
+  return std::array<HandshakeProtocol, 2>(
+      {PROTOCOL_QUIC_CRYPTO, PROTOCOL_TLS1_3});
+}
 
-static const std::array<ParsedQuicVersion, 7> kSupportedVersions = {
-    ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_50),
-    ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_49),
-    ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_48),
-    ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_46),
-    ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_43),
-    ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_99),
-    ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_50),
-};
+constexpr std::array<ParsedQuicVersion, 7> SupportedVersions() {
+  return std::array<ParsedQuicVersion, 7>({
+      ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_50),
+      ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_49),
+      ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_48),
+      ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_46),
+      ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_43),
+      ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_99),
+      ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_50),
+  });
+}
 
-typedef std::vector<QuicTransportVersion> QuicTransportVersionVector;
+using QuicTransportVersionVector = std::vector<QuicTransportVersion>;
 
 // Returns a vector of QUIC versions in kSupportedTransportVersions.
 QUIC_EXPORT_PRIVATE QuicTransportVersionVector AllSupportedTransportVersions();
diff --git a/quic/core/quic_versions_test.cc b/quic/core/quic_versions_test.cc
index cc7bf05..ae48f1b 100644
--- a/quic/core/quic_versions_test.cc
+++ b/quic/core/quic_versions_test.cc
@@ -41,8 +41,7 @@
   // Loop over all supported versions and make sure that we never hit the
   // default case (i.e. all supported versions should be successfully converted
   // to valid QuicVersionLabels).
-  for (size_t i = 0; i < QUICHE_ARRAYSIZE(kSupportedTransportVersions); ++i) {
-    QuicTransportVersion transport_version = kSupportedTransportVersions[i];
+  for (QuicTransportVersion transport_version : SupportedTransportVersions()) {
     if (!ParsedQuicVersionIsValid(PROTOCOL_QUIC_CRYPTO, transport_version)) {
       continue;
     }
@@ -85,8 +84,7 @@
   EXPECT_EQ(QUIC_VERSION_43,
             QuicVersionLabelToQuicVersion(MakeQuicTag('3', '4', '0', 'Q')));
 
-  for (size_t i = 0; i < QUICHE_ARRAYSIZE(kSupportedTransportVersions); ++i) {
-    QuicTransportVersion transport_version = kSupportedTransportVersions[i];
+  for (QuicTransportVersion transport_version : SupportedTransportVersions()) {
     if (!ParsedQuicVersionIsValid(PROTOCOL_QUIC_CRYPTO, transport_version)) {
       continue;
     }
@@ -240,9 +238,9 @@
             QuicTransportVersionVectorToString(versions_vector));
 
   // Make sure that all supported versions are present in QuicVersionToString.
-  for (size_t i = 0; i < QUICHE_ARRAYSIZE(kSupportedTransportVersions); ++i) {
-    QuicTransportVersion version = kSupportedTransportVersions[i];
-    EXPECT_NE("QUIC_VERSION_UNSUPPORTED", QuicVersionToString(version));
+  for (QuicTransportVersion transport_version : SupportedTransportVersions()) {
+    EXPECT_NE("QUIC_VERSION_UNSUPPORTED",
+              QuicVersionToString(transport_version));
   }
 }
 
@@ -269,7 +267,7 @@
 }
 
 TEST_F(QuicVersionsTest, FilterSupportedVersionsAllVersions) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync");
   SetQuicReloadableFlag(quic_enable_version_t099, true);
   SetQuicReloadableFlag(quic_enable_version_t050, true);
@@ -301,7 +299,7 @@
 }
 
 TEST_F(QuicVersionsTest, FilterSupportedVersionsNo99) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync");
   SetQuicReloadableFlag(quic_enable_version_t099, false);
   SetQuicReloadableFlag(quic_enable_version_t050, true);
@@ -330,7 +328,7 @@
 }
 
 TEST_F(QuicVersionsTest, FilterSupportedVersionsNoFlags) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync");
   SetQuicReloadableFlag(quic_enable_version_t099, false);
   SetQuicReloadableFlag(quic_enable_version_t050, false);
@@ -395,7 +393,7 @@
 // yet a typo was made in doing the #defines and it was caught
 // only in some test far removed from here... Better safe than sorry.
 TEST_F(QuicVersionsTest, CheckVersionNumbersForTypos) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync");
   EXPECT_EQ(QUIC_VERSION_43, 43);
   EXPECT_EQ(QUIC_VERSION_46, 46);
@@ -406,7 +404,7 @@
 }
 
 TEST_F(QuicVersionsTest, AlpnForVersion) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync");
   ParsedQuicVersion parsed_version_q048 =
       ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_48);
@@ -429,7 +427,7 @@
 }
 
 TEST_F(QuicVersionsTest, QuicEnableVersion) {
-  static_assert(QUICHE_ARRAYSIZE(kSupportedTransportVersions) == 6u,
+  static_assert(SupportedTransportVersions().size() == 6u,
                 "Supported versions out of sync");
   ParsedQuicVersion parsed_version_t099 =
       ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_99);
@@ -465,25 +463,25 @@
             QuicVersionReservedForNegotiation().transport_version);
   // QUIC_VERSION_RESERVED_FOR_NEGOTIATION MUST NOT be added to
   // kSupportedTransportVersions.
-  for (size_t i = 0; i < QUICHE_ARRAYSIZE(kSupportedTransportVersions); ++i) {
-    EXPECT_NE(QUIC_VERSION_RESERVED_FOR_NEGOTIATION,
-              kSupportedTransportVersions[i]);
+  for (QuicTransportVersion transport_version : SupportedTransportVersions()) {
+    EXPECT_NE(QUIC_VERSION_RESERVED_FOR_NEGOTIATION, transport_version);
   }
 }
 
 TEST_F(QuicVersionsTest, SupportedVersionsHasCorrectList) {
   size_t index = 0;
-  for (HandshakeProtocol handshake_protocol : kSupportedHandshakeProtocols) {
-    for (QuicTransportVersion transport_version : kSupportedTransportVersions) {
+  for (HandshakeProtocol handshake_protocol : SupportedHandshakeProtocols()) {
+    for (QuicTransportVersion transport_version :
+         SupportedTransportVersions()) {
       SCOPED_TRACE(index);
       if (ParsedQuicVersionIsValid(handshake_protocol, transport_version)) {
-        EXPECT_EQ(kSupportedVersions[index],
+        EXPECT_EQ(SupportedVersions()[index],
                   ParsedQuicVersion(handshake_protocol, transport_version));
         index++;
       }
     }
   }
-  EXPECT_EQ(kSupportedVersions.size(), index);
+  EXPECT_EQ(SupportedVersions().size(), index);
 }
 
 }  // namespace
diff --git a/quic/test_tools/quic_test_utils.cc b/quic/test_tools/quic_test_utils.cc
index dbb4165..4a9bac5 100644
--- a/quic/test_tools/quic_test_utils.cc
+++ b/quic/test_tools/quic_test_utils.cc
@@ -1028,13 +1028,6 @@
   return config;
 }
 
-QuicTransportVersionVector SupportedTransportVersions(
-    QuicTransportVersion version) {
-  QuicTransportVersionVector versions;
-  versions.push_back(version);
-  return versions;
-}
-
 ParsedQuicVersionVector SupportedVersions(ParsedQuicVersion version) {
   ParsedQuicVersionVector versions;
   versions.push_back(version);
diff --git a/quic/test_tools/quic_test_utils.h b/quic/test_tools/quic_test_utils.h
index 8ca2884..8eb117f 100644
--- a/quic/test_tools/quic_test_utils.h
+++ b/quic/test_tools/quic_test_utils.h
@@ -168,10 +168,6 @@
 // Returns QuicConfig set to default values.
 QuicConfig DefaultQuicConfig();
 
-// Returns a version vector consisting of |version|.
-QuicTransportVersionVector SupportedTransportVersions(
-    QuicTransportVersion version);
-
 ParsedQuicVersionVector SupportedVersions(ParsedQuicVersion version);
 
 struct QuicAckBlock {