unused.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef RTC_BASE_SYSTEM_UNUSED_H_
  11. #define RTC_BASE_SYSTEM_UNUSED_H_
  12. // Annotate a function indicating the caller must examine the return value.
  13. // Use like:
  14. // int foo() RTC_WARN_UNUSED_RESULT;
  15. // To explicitly ignore a result, cast to void.
  16. // TODO(kwiberg): Remove when we can use [[nodiscard]] from C++17.
  17. #if defined(__clang__)
  18. #define RTC_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
  19. #elif defined(__GNUC__)
  20. // gcc has a __warn_unused_result__ attribute, but you can't quiet it by
  21. // casting to void, so we don't use it.
  22. #define RTC_WARN_UNUSED_RESULT
  23. #else
  24. #define RTC_WARN_UNUSED_RESULT
  25. #endif
  26. // Prevent the compiler from warning about an unused variable. For example:
  27. // int result = DoSomething();
  28. // assert(result == 17);
  29. // RTC_UNUSED(result);
  30. // Note: In most cases it is better to remove the unused variable rather than
  31. // suppressing the compiler warning.
  32. #ifndef RTC_UNUSED
  33. #define RTC_UNUSED(x) static_cast<void>(x)
  34. #endif // RTC_UNUSED
  35. #endif // RTC_BASE_SYSTEM_UNUSED_H_