check_op.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. // Copyright 2022 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. // -----------------------------------------------------------------------------
  16. // File: log/internal/check_op.h
  17. // -----------------------------------------------------------------------------
  18. //
  19. // This file declares helpers routines and macros used to implement `CHECK`
  20. // macros.
  21. #ifndef ABSL_LOG_INTERNAL_CHECK_OP_H_
  22. #define ABSL_LOG_INTERNAL_CHECK_OP_H_
  23. #include <stdint.h>
  24. #include <cstddef>
  25. #include <ostream>
  26. #include <sstream>
  27. #include <string>
  28. #include <type_traits>
  29. #include <utility>
  30. #include "absl/base/attributes.h"
  31. #include "absl/base/config.h"
  32. #include "absl/base/optimization.h"
  33. #include "absl/log/internal/nullguard.h"
  34. #include "absl/log/internal/nullstream.h"
  35. #include "absl/log/internal/strip.h"
  36. #include "absl/strings/has_absl_stringify.h"
  37. #include "absl/strings/string_view.h"
  38. // `ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL` wraps string literals that
  39. // should be stripped when `ABSL_MIN_LOG_LEVEL` exceeds `kFatal`.
  40. #ifdef ABSL_MIN_LOG_LEVEL
  41. #define ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(literal) \
  42. (::absl::LogSeverity::kFatal >= \
  43. static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL) \
  44. ? (literal) \
  45. : "")
  46. #else
  47. #define ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(literal) (literal)
  48. #endif
  49. #ifdef NDEBUG
  50. // `NDEBUG` is defined, so `DCHECK_EQ(x, y)` and so on do nothing. However, we
  51. // still want the compiler to parse `x` and `y`, because we don't want to lose
  52. // potentially useful errors and warnings.
  53. #define ABSL_LOG_INTERNAL_DCHECK_NOP(x, y) \
  54. while (false && ((void)(x), (void)(y), 0)) \
  55. ::absl::log_internal::NullStream().InternalStream()
  56. #endif
  57. #define ABSL_LOG_INTERNAL_CHECK_OP(name, op, val1, val1_text, val2, val2_text) \
  58. while (::std::string* absl_log_internal_check_op_result \
  59. ABSL_LOG_INTERNAL_ATTRIBUTE_UNUSED_IF_STRIP_LOG = \
  60. ::absl::log_internal::name##Impl( \
  61. ::absl::log_internal::GetReferenceableValue(val1), \
  62. ::absl::log_internal::GetReferenceableValue(val2), \
  63. ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL( \
  64. val1_text " " #op " " val2_text))) \
  65. ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, true) \
  66. ABSL_LOG_INTERNAL_CHECK(*absl_log_internal_check_op_result).InternalStream()
  67. #define ABSL_LOG_INTERNAL_QCHECK_OP(name, op, val1, val1_text, val2, \
  68. val2_text) \
  69. while (::std::string* absl_log_internal_qcheck_op_result = \
  70. ::absl::log_internal::name##Impl( \
  71. ::absl::log_internal::GetReferenceableValue(val1), \
  72. ::absl::log_internal::GetReferenceableValue(val2), \
  73. ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL( \
  74. val1_text " " #op " " val2_text))) \
  75. ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, true) \
  76. ABSL_LOG_INTERNAL_QCHECK(*absl_log_internal_qcheck_op_result).InternalStream()
  77. #define ABSL_LOG_INTERNAL_CHECK_STROP(func, op, expected, s1, s1_text, s2, \
  78. s2_text) \
  79. while (::std::string* absl_log_internal_check_strop_result = \
  80. ::absl::log_internal::Check##func##expected##Impl( \
  81. (s1), (s2), \
  82. ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(s1_text " " #op \
  83. " " s2_text))) \
  84. ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, true) \
  85. ABSL_LOG_INTERNAL_CHECK(*absl_log_internal_check_strop_result) \
  86. .InternalStream()
  87. #define ABSL_LOG_INTERNAL_QCHECK_STROP(func, op, expected, s1, s1_text, s2, \
  88. s2_text) \
  89. while (::std::string* absl_log_internal_qcheck_strop_result = \
  90. ::absl::log_internal::Check##func##expected##Impl( \
  91. (s1), (s2), \
  92. ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(s1_text " " #op \
  93. " " s2_text))) \
  94. ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, true) \
  95. ABSL_LOG_INTERNAL_QCHECK(*absl_log_internal_qcheck_strop_result) \
  96. .InternalStream()
  97. // This one is tricky:
  98. // * We must evaluate `val` exactly once, yet we need to do two things with it:
  99. // evaluate `.ok()` and (sometimes) `.ToString()`.
  100. // * `val` might be an `absl::Status` or some `absl::StatusOr<T>`.
  101. // * `val` might be e.g. `ATemporary().GetStatus()`, which may return a
  102. // reference to a member of `ATemporary` that is only valid until the end of
  103. // the full expression.
  104. // * We don't want this file to depend on `absl::Status` `#include`s or linkage,
  105. // nor do we want to move the definition to status and introduce a dependency
  106. // in the other direction. We can be assured that callers must already have a
  107. // `Status` and the necessary `#include`s and linkage.
  108. // * Callsites should be small and fast (at least when `val.ok()`): one branch,
  109. // minimal stack footprint.
  110. // * In particular, the string concat stuff should be out-of-line and emitted
  111. // in only one TU to save linker input size
  112. // * We want the `val.ok()` check inline so static analyzers and optimizers can
  113. // see it.
  114. // * As usual, no braces so we can stream into the expansion with `operator<<`.
  115. // * Also as usual, it must expand to a single (partial) statement with no
  116. // ambiguous-else problems.
  117. // * When stripped by `ABSL_MIN_LOG_LEVEL`, we must discard the `<expr> is OK`
  118. // string literal and abort without doing any streaming. We don't need to
  119. // strip the call to stringify the non-ok `Status` as long as we don't log it;
  120. // dropping the `Status`'s message text is out of scope.
  121. #define ABSL_LOG_INTERNAL_CHECK_OK(val, val_text) \
  122. for (::std::pair<const ::absl::Status*, ::std::string*> \
  123. absl_log_internal_check_ok_goo; \
  124. absl_log_internal_check_ok_goo.first = \
  125. ::absl::log_internal::AsStatus(val), \
  126. absl_log_internal_check_ok_goo.second = \
  127. ABSL_PREDICT_TRUE(absl_log_internal_check_ok_goo.first->ok()) \
  128. ? nullptr \
  129. : ::absl::status_internal::MakeCheckFailString( \
  130. absl_log_internal_check_ok_goo.first, \
  131. ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(val_text \
  132. " is OK")), \
  133. !ABSL_PREDICT_TRUE(absl_log_internal_check_ok_goo.first->ok());) \
  134. ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, true) \
  135. ABSL_LOG_INTERNAL_CHECK(*absl_log_internal_check_ok_goo.second) \
  136. .InternalStream()
  137. #define ABSL_LOG_INTERNAL_QCHECK_OK(val, val_text) \
  138. for (::std::pair<const ::absl::Status*, ::std::string*> \
  139. absl_log_internal_qcheck_ok_goo; \
  140. absl_log_internal_qcheck_ok_goo.first = \
  141. ::absl::log_internal::AsStatus(val), \
  142. absl_log_internal_qcheck_ok_goo.second = \
  143. ABSL_PREDICT_TRUE(absl_log_internal_qcheck_ok_goo.first->ok()) \
  144. ? nullptr \
  145. : ::absl::status_internal::MakeCheckFailString( \
  146. absl_log_internal_qcheck_ok_goo.first, \
  147. ABSL_LOG_INTERNAL_STRIP_STRING_LITERAL(val_text \
  148. " is OK")), \
  149. !ABSL_PREDICT_TRUE(absl_log_internal_qcheck_ok_goo.first->ok());) \
  150. ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, true) \
  151. ABSL_LOG_INTERNAL_QCHECK(*absl_log_internal_qcheck_ok_goo.second) \
  152. .InternalStream()
  153. namespace absl {
  154. ABSL_NAMESPACE_BEGIN
  155. class Status;
  156. template <typename T>
  157. class StatusOr;
  158. namespace status_internal {
  159. ABSL_ATTRIBUTE_PURE_FUNCTION std::string* MakeCheckFailString(
  160. const absl::Status* status, const char* prefix);
  161. } // namespace status_internal
  162. namespace log_internal {
  163. // Convert a Status or a StatusOr to its underlying status value.
  164. //
  165. // (This implementation does not require a dep on absl::Status to work.)
  166. inline const absl::Status* AsStatus(const absl::Status& s) { return &s; }
  167. template <typename T>
  168. const absl::Status* AsStatus(const absl::StatusOr<T>& s) {
  169. return &s.status();
  170. }
  171. // A helper class for formatting `expr (V1 vs. V2)` in a `CHECK_XX` statement.
  172. // See `MakeCheckOpString` for sample usage.
  173. class CheckOpMessageBuilder final {
  174. public:
  175. // Inserts `exprtext` and ` (` to the stream.
  176. explicit CheckOpMessageBuilder(const char* exprtext);
  177. ~CheckOpMessageBuilder() = default;
  178. // For inserting the first variable.
  179. std::ostream& ForVar1() { return stream_; }
  180. // For inserting the second variable (adds an intermediate ` vs. `).
  181. std::ostream& ForVar2();
  182. // Get the result (inserts the closing `)`).
  183. std::string* NewString();
  184. private:
  185. std::ostringstream stream_;
  186. };
  187. // This formats a value for a failing `CHECK_XX` statement. Ordinarily, it uses
  188. // the definition for `operator<<`, with a few special cases below.
  189. template <typename T>
  190. inline void MakeCheckOpValueString(std::ostream& os, const T& v) {
  191. os << log_internal::NullGuard<T>::Guard(v);
  192. }
  193. // Overloads for char types provide readable values for unprintable characters.
  194. void MakeCheckOpValueString(std::ostream& os, char v);
  195. void MakeCheckOpValueString(std::ostream& os, signed char v);
  196. void MakeCheckOpValueString(std::ostream& os, unsigned char v);
  197. void MakeCheckOpValueString(std::ostream& os, const void* p);
  198. namespace detect_specialization {
  199. // MakeCheckOpString is being specialized for every T and U pair that is being
  200. // passed to the CHECK_op macros. However, there is a lot of redundancy in these
  201. // specializations that creates unnecessary library and binary bloat.
  202. // The number of instantiations tends to be O(n^2) because we have two
  203. // independent inputs. This technique works by reducing `n`.
  204. //
  205. // Most user-defined types being passed to CHECK_op end up being printed as a
  206. // builtin type. For example, enums tend to be implicitly converted to its
  207. // underlying type when calling operator<<, and pointers are printed with the
  208. // `const void*` overload.
  209. // To reduce the number of instantiations we coerce these values before calling
  210. // MakeCheckOpString instead of inside it.
  211. //
  212. // To detect if this coercion is needed, we duplicate all the relevant
  213. // operator<< overloads as specified in the standard, just in a different
  214. // namespace. If the call to `stream << value` becomes ambiguous, it means that
  215. // one of these overloads is the one selected by overload resolution. We then
  216. // do overload resolution again just with our overload set to see which one gets
  217. // selected. That tells us which type to coerce to.
  218. // If the augmented call was not ambiguous, it means that none of these were
  219. // selected and we can't coerce the input.
  220. //
  221. // As a secondary step to reduce code duplication, we promote integral types to
  222. // their 64-bit variant. This does not change the printed value, but reduces the
  223. // number of instantiations even further. Promoting an integer is very cheap at
  224. // the call site.
  225. int64_t operator<<(std::ostream&, short value); // NOLINT
  226. int64_t operator<<(std::ostream&, unsigned short value); // NOLINT
  227. int64_t operator<<(std::ostream&, int value);
  228. int64_t operator<<(std::ostream&, unsigned int value);
  229. int64_t operator<<(std::ostream&, long value); // NOLINT
  230. uint64_t operator<<(std::ostream&, unsigned long value); // NOLINT
  231. int64_t operator<<(std::ostream&, long long value); // NOLINT
  232. uint64_t operator<<(std::ostream&, unsigned long long value); // NOLINT
  233. float operator<<(std::ostream&, float value);
  234. double operator<<(std::ostream&, double value);
  235. long double operator<<(std::ostream&, long double value);
  236. bool operator<<(std::ostream&, bool value);
  237. const void* operator<<(std::ostream&, const void* value);
  238. const void* operator<<(std::ostream&, std::nullptr_t);
  239. // These `char` overloads are specified like this in the standard, so we have to
  240. // write them exactly the same to ensure the call is ambiguous.
  241. // If we wrote it in a different way (eg taking std::ostream instead of the
  242. // template) then one call might have a higher rank than the other and it would
  243. // not be ambiguous.
  244. template <typename Traits>
  245. char operator<<(std::basic_ostream<char, Traits>&, char);
  246. template <typename Traits>
  247. signed char operator<<(std::basic_ostream<char, Traits>&, signed char);
  248. template <typename Traits>
  249. unsigned char operator<<(std::basic_ostream<char, Traits>&, unsigned char);
  250. template <typename Traits>
  251. const char* operator<<(std::basic_ostream<char, Traits>&, const char*);
  252. template <typename Traits>
  253. const signed char* operator<<(std::basic_ostream<char, Traits>&,
  254. const signed char*);
  255. template <typename Traits>
  256. const unsigned char* operator<<(std::basic_ostream<char, Traits>&,
  257. const unsigned char*);
  258. // This overload triggers when the call is not ambiguous.
  259. // It means that T is being printed with some overload not on this list.
  260. // We keep the value as `const T&`.
  261. template <typename T, typename = decltype(std::declval<std::ostream&>()
  262. << std::declval<const T&>())>
  263. const T& Detect(int);
  264. // This overload triggers when the call is ambiguous.
  265. // It means that T is either one from this list or printed as one from this
  266. // list. Eg an enum that decays to `int` for printing.
  267. // We ask the overload set to give us the type we want to convert it to.
  268. template <typename T>
  269. decltype(detect_specialization::operator<<(std::declval<std::ostream&>(),
  270. std::declval<const T&>()))
  271. Detect(char);
  272. // A sink for AbslStringify which redirects everything to a std::ostream.
  273. class StringifySink {
  274. public:
  275. explicit StringifySink(std::ostream& os ABSL_ATTRIBUTE_LIFETIME_BOUND);
  276. void Append(absl::string_view text);
  277. void Append(size_t length, char ch);
  278. friend void AbslFormatFlush(StringifySink* sink, absl::string_view text);
  279. private:
  280. std::ostream& os_;
  281. };
  282. // Wraps a type implementing AbslStringify, and implements operator<<.
  283. template <typename T>
  284. class StringifyToStreamWrapper {
  285. public:
  286. explicit StringifyToStreamWrapper(const T& v ABSL_ATTRIBUTE_LIFETIME_BOUND)
  287. : v_(v) {}
  288. friend std::ostream& operator<<(std::ostream& os,
  289. const StringifyToStreamWrapper& wrapper) {
  290. StringifySink sink(os);
  291. AbslStringify(sink, wrapper.v_);
  292. return os;
  293. }
  294. private:
  295. const T& v_;
  296. };
  297. // This overload triggers when T implements AbslStringify.
  298. // StringifyToStreamWrapper is used to allow MakeCheckOpString to use
  299. // operator<<.
  300. template <typename T>
  301. std::enable_if_t<HasAbslStringify<T>::value,
  302. StringifyToStreamWrapper<T>>
  303. Detect(...); // Ellipsis has lowest preference when int passed.
  304. } // namespace detect_specialization
  305. template <typename T>
  306. using CheckOpStreamType = decltype(detect_specialization::Detect<T>(0));
  307. // Build the error message string. Specify no inlining for code size.
  308. template <typename T1, typename T2>
  309. ABSL_ATTRIBUTE_RETURNS_NONNULL std::string* MakeCheckOpString(
  310. T1 v1, T2 v2, const char* exprtext) ABSL_ATTRIBUTE_NOINLINE;
  311. template <typename T1, typename T2>
  312. std::string* MakeCheckOpString(T1 v1, T2 v2, const char* exprtext) {
  313. CheckOpMessageBuilder comb(exprtext);
  314. MakeCheckOpValueString(comb.ForVar1(), v1);
  315. MakeCheckOpValueString(comb.ForVar2(), v2);
  316. return comb.NewString();
  317. }
  318. // Add a few commonly used instantiations as extern to reduce size of objects
  319. // files.
  320. #define ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(x) \
  321. extern template std::string* MakeCheckOpString(x, x, const char*)
  322. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(bool);
  323. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(int64_t);
  324. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(uint64_t);
  325. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(float);
  326. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(double);
  327. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(char);
  328. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(unsigned char);
  329. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const std::string&);
  330. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const absl::string_view&);
  331. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const char*);
  332. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const signed char*);
  333. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const unsigned char*);
  334. ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN(const void*);
  335. #undef ABSL_LOG_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING_EXTERN
  336. // `ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT` skips formatting the Check_OP result
  337. // string iff `ABSL_MIN_LOG_LEVEL` exceeds `kFatal`, instead returning an empty
  338. // string.
  339. #ifdef ABSL_MIN_LOG_LEVEL
  340. #define ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT(U1, U2, v1, v2, exprtext) \
  341. ((::absl::LogSeverity::kFatal >= \
  342. static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL)) \
  343. ? MakeCheckOpString<U1, U2>(v1, v2, exprtext) \
  344. : new std::string())
  345. #else
  346. #define ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT(U1, U2, v1, v2, exprtext) \
  347. MakeCheckOpString<U1, U2>(v1, v2, exprtext)
  348. #endif
  349. // Helper functions for `ABSL_LOG_INTERNAL_CHECK_OP` macro family. The
  350. // `(int, int)` override works around the issue that the compiler will not
  351. // instantiate the template version of the function on values of unnamed enum
  352. // type.
  353. #define ABSL_LOG_INTERNAL_CHECK_OP_IMPL(name, op) \
  354. template <typename T1, typename T2> \
  355. inline constexpr ::std::string* name##Impl(const T1& v1, const T2& v2, \
  356. const char* exprtext) { \
  357. using U1 = CheckOpStreamType<T1>; \
  358. using U2 = CheckOpStreamType<T2>; \
  359. return ABSL_PREDICT_TRUE(v1 op v2) \
  360. ? nullptr \
  361. : ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT(U1, U2, U1(v1), \
  362. U2(v2), exprtext); \
  363. } \
  364. inline constexpr ::std::string* name##Impl(int v1, int v2, \
  365. const char* exprtext) { \
  366. return name##Impl<int, int>(v1, v2, exprtext); \
  367. }
  368. ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_EQ, ==)
  369. ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_NE, !=)
  370. ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_LE, <=)
  371. ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_LT, <)
  372. ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_GE, >=)
  373. ABSL_LOG_INTERNAL_CHECK_OP_IMPL(Check_GT, >)
  374. #undef ABSL_LOG_INTERNAL_CHECK_OP_IMPL_RESULT
  375. #undef ABSL_LOG_INTERNAL_CHECK_OP_IMPL
  376. std::string* CheckstrcmptrueImpl(const char* s1, const char* s2,
  377. const char* exprtext);
  378. std::string* CheckstrcmpfalseImpl(const char* s1, const char* s2,
  379. const char* exprtext);
  380. std::string* CheckstrcasecmptrueImpl(const char* s1, const char* s2,
  381. const char* exprtext);
  382. std::string* CheckstrcasecmpfalseImpl(const char* s1, const char* s2,
  383. const char* exprtext);
  384. // `CHECK_EQ` and friends want to pass their arguments by reference, however
  385. // this winds up exposing lots of cases where people have defined and
  386. // initialized static const data members but never declared them (i.e. in a .cc
  387. // file), meaning they are not referenceable. This function avoids that problem
  388. // for integers (the most common cases) by overloading for every primitive
  389. // integer type, even the ones we discourage, and returning them by value.
  390. template <typename T>
  391. inline constexpr const T& GetReferenceableValue(const T& t) {
  392. return t;
  393. }
  394. inline constexpr char GetReferenceableValue(char t) { return t; }
  395. inline constexpr unsigned char GetReferenceableValue(unsigned char t) {
  396. return t;
  397. }
  398. inline constexpr signed char GetReferenceableValue(signed char t) { return t; }
  399. inline constexpr short GetReferenceableValue(short t) { return t; } // NOLINT
  400. inline constexpr unsigned short GetReferenceableValue( // NOLINT
  401. unsigned short t) { // NOLINT
  402. return t;
  403. }
  404. inline constexpr int GetReferenceableValue(int t) { return t; }
  405. inline constexpr unsigned int GetReferenceableValue(unsigned int t) {
  406. return t;
  407. }
  408. inline constexpr long GetReferenceableValue(long t) { return t; } // NOLINT
  409. inline constexpr unsigned long GetReferenceableValue( // NOLINT
  410. unsigned long t) { // NOLINT
  411. return t;
  412. }
  413. inline constexpr long long GetReferenceableValue(long long t) { // NOLINT
  414. return t;
  415. }
  416. inline constexpr unsigned long long GetReferenceableValue( // NOLINT
  417. unsigned long long t) { // NOLINT
  418. return t;
  419. }
  420. } // namespace log_internal
  421. ABSL_NAMESPACE_END
  422. } // namespace absl
  423. #endif // ABSL_LOG_INTERNAL_CHECK_OP_H_