In HashState::Create, require that T is a subclass of HashStateBase in order to discourage users from defining their own HashState types.

PiperOrigin-RevId: 712577158
Change-Id: Iae6d23d03f291b18104f3c6d5a5b17e0af7f222a
diff --git a/absl/hash/hash.h b/absl/hash/hash.h
index aea7e1f..3658aa5 100644
--- a/absl/hash/hash.h
+++ b/absl/hash/hash.h
@@ -80,11 +80,13 @@
 
 #include <cstddef>
 #include <tuple>
+#include <type_traits>
 #include <utility>
 
 #include "absl/base/config.h"
 #include "absl/functional/function_ref.h"
 #include "absl/hash/internal/hash.h"
+#include "absl/meta/type_traits.h"
 
 namespace absl {
 ABSL_NAMESPACE_BEGIN
@@ -321,8 +323,12 @@
   // Create a new `HashState` instance that wraps `state`. All calls to
   // `combine()` and `combine_contiguous()` on the new instance will be
   // redirected to the original `state` object. The `state` object must outlive
-  // the `HashState` instance.
-  template <typename T>
+  // the `HashState` instance. `T` must be a subclass of `HashStateBase<T>` -
+  // users should not define their own HashState types.
+  template <
+      typename T,
+      absl::enable_if_t<
+          std::is_base_of<hash_internal::HashStateBase<T>, T>::value, int> = 0>
   static HashState Create(T* state) {
     HashState s;
     s.Init(state);