Fallthrough.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //===--- Fallthrough.h - switch fallthrough annotation macro ----*- C++ -*-===//
  2. //
  3. // This source file is part of the Swift.org open source project
  4. //
  5. // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
  6. // Licensed under Apache License v2.0 with Runtime Library Exception
  7. //
  8. // See http://swift.org/LICENSE.txt for license information
  9. // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
  10. //
  11. //===----------------------------------------------------------------------===//
  12. //
  13. // This file defines a SWIFT_FALLTHROUGH macro to annotate intentional
  14. // fallthrough between switch cases. For compilers that support the
  15. // "clang::fallthrough" attribute, it expands to an empty statement with the
  16. // attribute applied; otherwise, it expands to just an empty statement.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef SWIFT_BASIC_FALLTHROUGH_H
  20. #define SWIFT_BASIC_FALLTHROUGH_H
  21. #ifndef __has_attribute
  22. # define __has_attribute(x) 0
  23. #endif
  24. #ifndef __has_cpp_attribute
  25. # define __has_cpp_attribute(x) 0
  26. #endif
  27. #if __has_attribute(fallthrough)
  28. # define SWIFT_FALLTHROUGH [[clang::fallthrough]]
  29. #elif __has_cpp_attribute(clang::fallthrough)
  30. # define SWIFT_FALLTHROUGH [[clang::fallthrough]]
  31. #else
  32. # define SWIFT_FALLTHROUGH
  33. #endif
  34. #endif // SWIFT_BASIC_FALLTHROUGH_H