Convert unnamed enums in third_party/quiche and third_party/http2 to constexpr variables. Modern C++ style prefers `constexpr` variables over unnamed enums for defining compile-time constants (go/totw/140). This change replaces instances of unnamed enums defining constants across QUICHE and HTTP2 libraries with their `constexpr` equivalents. Unnamed enums defined within classes are replaced with `static constexpr` variables, while those outside classes are replaced with `inline constexpr` variables. PiperOrigin-RevId: 927430492
diff --git a/quiche/common/quiche_data_writer.h b/quiche/common/quiche_data_writer.h index 94f8480..1060dbb 100644 --- a/quiche/common/quiche_data_writer.h +++ b/quiche/common/quiche_data_writer.h
@@ -19,21 +19,17 @@ // Maximum value that can be properly encoded using RFC 9000 62-bit Variable // Length Integer encoding. -enum : uint64_t { - kVarInt62MaxValue = UINT64_C(0x3fffffffffffffff), -}; +inline constexpr uint64_t kVarInt62MaxValue = UINT64_C(0x3fffffffffffffff); // RFC 9000 62-bit Variable Length Integer encoding masks // If a uint64_t anded with a mask is not 0 then the value is encoded // using that length (or is too big, in the case of kVarInt62ErrorMask). // Values must be checked in order (error, 8-, 4-, and then 2- bytes) // and if none are non-0, the value is encoded in 1 byte. -enum : uint64_t { - kVarInt62ErrorMask = UINT64_C(0xc000000000000000), - kVarInt62Mask8Bytes = UINT64_C(0x3fffffffc0000000), - kVarInt62Mask4Bytes = UINT64_C(0x000000003fffc000), - kVarInt62Mask2Bytes = UINT64_C(0x0000000000003fc0), -}; +inline constexpr uint64_t kVarInt62ErrorMask = UINT64_C(0xc000000000000000); +inline constexpr uint64_t kVarInt62Mask8Bytes = UINT64_C(0x3fffffffc0000000); +inline constexpr uint64_t kVarInt62Mask4Bytes = UINT64_C(0x000000003fffc000); +inline constexpr uint64_t kVarInt62Mask2Bytes = UINT64_C(0x0000000000003fc0); // This class provides facilities for packing binary data. //
diff --git a/quiche/common/quiche_ip_address.h b/quiche/common/quiche_ip_address.h index a6eeffd..ec18646 100644 --- a/quiche/common/quiche_ip_address.h +++ b/quiche/common/quiche_ip_address.h
@@ -28,11 +28,9 @@ class QUICHE_EXPORT QuicheIpAddress { public: // Sizes of IP addresses of different types, in bytes. - enum : size_t { - kIPv4AddressSize = 32 / 8, - kIPv6AddressSize = 128 / 8, - kMaxAddressSize = kIPv6AddressSize, - }; + static constexpr size_t kIPv4AddressSize = 32 / 8; + static constexpr size_t kIPv6AddressSize = 128 / 8; + static constexpr size_t kMaxAddressSize = kIPv6AddressSize; // TODO(fayang): Remove Loopback*() and use TestLoopback*() in tests. static QuicheIpAddress Loopback4();
diff --git a/quiche/http2/adapter/data_source.h b/quiche/http2/adapter/data_source.h index 589e768..2df11a2 100644 --- a/quiche/http2/adapter/data_source.h +++ b/quiche/http2/adapter/data_source.h
@@ -14,7 +14,8 @@ // TODO(birenroy): move the remaining constants. class QUICHE_EXPORT DataFrameSource { public: - enum : int64_t { kBlocked = 0, kError = -1 }; + static constexpr int64_t kBlocked = 0; + static constexpr int64_t kError = -1; }; // Represents a source of metadata frames for transmission to the peer.
diff --git a/quiche/http2/adapter/http2_visitor_interface.h b/quiche/http2/adapter/http2_visitor_interface.h index fffd59a..7cff2bf 100644 --- a/quiche/http2/adapter/http2_visitor_interface.h +++ b/quiche/http2/adapter/http2_visitor_interface.h
@@ -53,10 +53,8 @@ Http2VisitorInterface& operator=(const Http2VisitorInterface&) = delete; virtual ~Http2VisitorInterface() = default; - enum : int64_t { - kSendBlocked = 0, - kSendError = -1, - }; + static constexpr int64_t kSendBlocked = 0; + static constexpr int64_t kSendError = -1; // Called when there are serialized frames to send. Should return how many // bytes were actually sent. May return kSendBlocked or kSendError. virtual int64_t OnReadyToSend(absl::string_view serialized) = 0;