Coverage Report

Created: 2026-05-23 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/abseil-cpp/absl/cleanup/internal/cleanup.h
Line
Count
Source
1
// Copyright 2021 The Abseil Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef ABSL_CLEANUP_INTERNAL_CLEANUP_H_
16
#define ABSL_CLEANUP_INTERNAL_CLEANUP_H_
17
18
#include <new>
19
#include <type_traits>
20
#include <utility>
21
22
#include "absl/base/internal/hardening.h"
23
#include "absl/base/macros.h"
24
#include "absl/base/thread_annotations.h"
25
#include "absl/utility/utility.h"
26
27
namespace absl {
28
ABSL_NAMESPACE_BEGIN
29
30
namespace cleanup_internal {
31
32
struct Tag {};
33
34
template <typename Arg, typename... Args>
35
0
constexpr bool WasDeduced() {
36
0
  return (std::is_same<cleanup_internal::Tag, Arg>::value) &&
37
0
         (sizeof...(Args) == 0);
38
0
}
39
40
template <typename Callback>
41
0
constexpr bool ReturnsVoid() {
42
0
  return (std::is_same<std::invoke_result_t<Callback>, void>::value);
43
0
}
Unexecuted instantiation: log_sink_set.cc:bool absl::cleanup_internal::ReturnsVoid<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::LogToSinks(absl::LogEntry const&, absl::Span<absl::LogSink*>, bool)::{lambda()#1}>()
Unexecuted instantiation: log_sink_set.cc:bool absl::cleanup_internal::ReturnsVoid<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::FlushLogSinks()::{lambda()#1}>()
44
45
template <typename Callback>
46
class Storage {
47
 public:
48
  Storage() = delete;
49
50
0
  explicit Storage(Callback callback) {
51
    // Placement-new into a character buffer is used for eager destruction when
52
    // the cleanup is invoked or cancelled. To ensure this optimizes well, the
53
    // behavior is implemented locally instead of using a std::optional.
54
0
    ::new (GetCallbackBuffer()) Callback(std::move(callback));
55
0
    is_callback_engaged_ = true;
56
0
  }
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::LogToSinks(absl::LogEntry const&, absl::Span<absl::LogSink*>, bool)::{lambda()#1}>::Storage({lambda()#1})
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::FlushLogSinks()::{lambda()#1}>::Storage({lambda()#1})
57
58
  Storage(Storage&& other) {
59
    absl::base_internal::HardeningAssert(other.IsCallbackEngaged());
60
61
    ::new (GetCallbackBuffer()) Callback(std::move(other.GetCallback()));
62
    is_callback_engaged_ = true;
63
64
    other.DestroyCallback();
65
  }
66
67
  Storage(const Storage& other) = delete;
68
69
  Storage& operator=(Storage&& other) = delete;
70
71
  Storage& operator=(const Storage& other) = delete;
72
73
0
  void* GetCallbackBuffer() { return static_cast<void*>(callback_buffer_); }
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::LogToSinks(absl::LogEntry const&, absl::Span<absl::LogSink*>, bool)::{lambda()#1}>::GetCallbackBuffer()
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::FlushLogSinks()::{lambda()#1}>::GetCallbackBuffer()
74
75
0
  Callback& GetCallback() {
76
0
    return *reinterpret_cast<Callback*>(GetCallbackBuffer());
77
0
  }
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::LogToSinks(absl::LogEntry const&, absl::Span<absl::LogSink*>, bool)::{lambda()#1}>::GetCallback()
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::FlushLogSinks()::{lambda()#1}>::GetCallback()
78
79
0
  bool IsCallbackEngaged() const { return is_callback_engaged_; }
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::LogToSinks(absl::LogEntry const&, absl::Span<absl::LogSink*>, bool)::{lambda()#1}>::IsCallbackEngaged() const
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::FlushLogSinks()::{lambda()#1}>::IsCallbackEngaged() const
80
81
0
  void DestroyCallback() {
82
0
    is_callback_engaged_ = false;
83
0
    GetCallback().~Callback();
84
0
  }
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::LogToSinks(absl::LogEntry const&, absl::Span<absl::LogSink*>, bool)::{lambda()#1}>::DestroyCallback()
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::FlushLogSinks()::{lambda()#1}>::DestroyCallback()
85
86
0
  void InvokeCallback() ABSL_NO_THREAD_SAFETY_ANALYSIS {
87
0
    std::move(GetCallback())();
88
0
  }
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::LogToSinks(absl::LogEntry const&, absl::Span<absl::LogSink*>, bool)::{lambda()#1}>::InvokeCallback()
Unexecuted instantiation: log_sink_set.cc:absl::cleanup_internal::Storage<absl::log_internal::(anonymous namespace)::GlobalLogSinkSet::FlushLogSinks()::{lambda()#1}>::InvokeCallback()
89
90
 private:
91
  bool is_callback_engaged_;
92
  alignas(Callback) unsigned char callback_buffer_[sizeof(Callback)];
93
};
94
95
}  // namespace cleanup_internal
96
97
ABSL_NAMESPACE_END
98
}  // namespace absl
99
100
#endif  // ABSL_CLEANUP_INTERNAL_CLEANUP_H_