notreached.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/base_export.h"
  7. #include "base/check.h"
  8. #include "base/dcheck_is_on.h"
  9. #include "base/logging_buildflags.h"
  10. namespace logging {
  11. // Under these conditions NOTREACHED() will effectively either log or DCHECK.
  12. #if BUILDFLAG(ENABLE_LOG_ERROR_NOT_REACHED) || DCHECK_IS_ON()
  13. #define NOTREACHED() \
  14. LAZY_CHECK_STREAM( \
  15. ::logging::CheckError::NotReached(__FILE__, __LINE__).stream(), true)
  16. #else
  17. #define NOTREACHED() EAT_CHECK_STREAM_PARAMS()
  18. #endif // BUILDFLAG(ENABLE_LOG_ERROR_NOT_REACHED) || DCHECK_IS_ON()
  19. // The NOTIMPLEMENTED() macro annotates codepaths which have not been
  20. // implemented yet. If output spam is a serious concern,
  21. // NOTIMPLEMENTED_LOG_ONCE can be used.
  22. #if DCHECK_IS_ON()
  23. #define NOTIMPLEMENTED() \
  24. ::logging::CheckError::NotImplemented(__FILE__, __LINE__, \
  25. __PRETTY_FUNCTION__) \
  26. .stream()
  27. #else
  28. #define NOTIMPLEMENTED() EAT_CHECK_STREAM_PARAMS()
  29. #endif
  30. #define NOTIMPLEMENTED_LOG_ONCE() \
  31. { \
  32. static bool logged_once = false; \
  33. if (!logged_once) { \
  34. NOTIMPLEMENTED(); \
  35. logged_once = true; \
  36. } \
  37. } \
  38. EAT_CHECK_STREAM_PARAMS()
  39. } // namespace logging
  40. #endif // BASE_NOTREACHED_H_