2828#include < type_traits>
2929#include < utility>
3030
31+ #include " absl/base/dynamic_annotations.h"
3132#include " absl/base/optimization.h"
3233#include " absl/container/node_hash_map.h"
3334#include " absl/debugging/leak_check.h"
@@ -88,6 +89,7 @@ size_t MetricThreadCounter();
8889template <typename T>
8990T* LazyInit (std::atomic<T*>& ptr) {
9091 T* p = ptr.load (std::memory_order_acquire);
92+ ABSL_ANNOTATE_MEMORY_IS_INITIALIZED (&p, sizeof (p));
9193 if (ABSL_PREDICT_FALSE (!p)) {
9294 auto * candidate = absl::IgnoreLeak (new T ());
9395 T* expected = nullptr ;
@@ -326,8 +328,7 @@ class AbstractMetric {
326328 using field_values_type = typename Key::tuple_type;
327329 using value_type = typename Cell::value_type;
328330
329- constexpr AbstractMetric () : state_(nullptr ) {}
330-
331+ constexpr AbstractMetric () = default;
331332 ~AbstractMetric () {
332333 // NOTE: State* should be "eternal", so we just leak it.
333334 }
@@ -384,14 +385,14 @@ class AbstractMetric {
384385 private:
385386 State* GetState () const { return LazyInit (state_); }
386387
387- mutable std::atomic<State*> state_;
388+ mutable std::atomic<State*> state_{ nullptr } ;
388389};
389390
390391// Lock-free Specialization for no fields using a sharded counter.
391392template <typename Cell>
392393class AbstractMetric <Cell, true > {
393394 public:
394- static constexpr bool kNumThreads = 4 ;
395+ static constexpr size_t kNumThreads = 4 ;
395396 using field_values_type = std::tuple<>;
396397 using value_type = typename Cell::value_type;
397398
@@ -432,7 +433,7 @@ class AbstractMetric<Cell, true> {
432433template <typename Cell, typename Enable = void >
433434class CellStorage {
434435 public:
435- constexpr CellStorage () : value_() {}
436+ constexpr CellStorage () = default;
436437 ~CellStorage () = default ;
437438
438439 Cell* Get () const { return &value_; }
@@ -447,7 +448,7 @@ template <typename Cell>
447448class CellStorage <Cell,
448449 std::enable_if_t <!std::is_trivially_destructible_v<Cell>>> {
449450 public:
450- constexpr CellStorage () : ptr_( nullptr ) {}
451+ constexpr CellStorage () = default;
451452 ~CellStorage () {
452453 // NOTE: Cell* should be "eternal", so we just leak it.
453454 }
@@ -462,7 +463,7 @@ class CellStorage<Cell,
462463 }
463464
464465 private:
465- mutable std::atomic<Cell*> ptr_;
466+ mutable std::atomic<Cell*> ptr_{ nullptr } ;
466467};
467468
468469// Lock-free Specialization for no fields.
0 commit comments