no_unique_address.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2020 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_NO_UNIQUE_ADDRESS_H_
  11. #define RTC_BASE_SYSTEM_NO_UNIQUE_ADDRESS_H_
  12. // RTC_NO_UNIQUE_ADDRESS is a portable annotation to tell the compiler that
  13. // a data member need not have an address distinct from all other non-static
  14. // data members of its class.
  15. // It allows empty types to actually occupy zero bytes as class members,
  16. // instead of occupying at least one byte just so that they get their own
  17. // address. There is almost never any reason not to use it on class members
  18. // that could possibly be empty.
  19. // The macro expands to [[no_unique_address]] if the compiler supports the
  20. // attribute, it expands to nothing otherwise.
  21. // Clang should supports this attribute since C++11, while other compilers
  22. // should add support for it starting from C++20. Among clang compilers,
  23. // clang-cl doesn't support it yet and support is unclear also when the target
  24. // platform is iOS.
  25. #if (defined(__clang__) && !defined(_MSC_VER) && !defined(WEBRTC_IOS)) || \
  26. __cplusplus > 201703L
  27. // NOLINTNEXTLINE(whitespace/braces)
  28. #define RTC_NO_UNIQUE_ADDRESS [[no_unique_address]]
  29. #else
  30. #define RTC_NO_UNIQUE_ADDRESS
  31. #endif
  32. #endif // RTC_BASE_SYSTEM_NO_UNIQUE_ADDRESS_H_