notreached.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_NOTREACHED_H_
  5. #define BASE_NOTREACHED_H_
  6. #include "base/check.h"
  7. #include "base/logging_buildflags.h"
  8. namespace logging {
  9. #if BUILDFLAG(ENABLE_LOG_ERROR_NOT_REACHED)
  10. void BASE_EXPORT LogErrorNotReached(const char* file, int line);
  11. #define NOTREACHED() \
  12. true ? ::logging::LogErrorNotReached(__FILE__, __LINE__) \
  13. : EAT_CHECK_STREAM_PARAMS()
  14. #else
  15. #define NOTREACHED() DCHECK(false)
  16. #endif
  17. // The NOTIMPLEMENTED() macro annotates codepaths which have not been
  18. // implemented yet. If output spam is a serious concern,
  19. // NOTIMPLEMENTED_LOG_ONCE can be used.
  20. #if DCHECK_IS_ON()
  21. #define NOTIMPLEMENTED() \
  22. ::logging::CheckError::NotImplemented(__FILE__, __LINE__, \
  23. __PRETTY_FUNCTION__) \
  24. .stream()
  25. #else
  26. #define NOTIMPLEMENTED() EAT_CHECK_STREAM_PARAMS()
  27. #endif
  28. #define NOTIMPLEMENTED_LOG_ONCE() \
  29. { \
  30. static bool logged_once = false; \
  31. if (!logged_once) { \
  32. NOTIMPLEMENTED(); \
  33. logged_once = true; \
  34. } \
  35. } \
  36. EAT_CHECK_STREAM_PARAMS()
  37. } // namespace logging
  38. #endif // BASE_NOTREACHED_H_