layout.carbon 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/class/export/layout.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/export/layout.carbon
  12. // --- simple.carbon
  13. library "[[@TEST_NAME]]";
  14. import Cpp;
  15. class C {
  16. var a: i32;
  17. var b: i32;
  18. var c: i32;
  19. }
  20. inline Cpp '''c++
  21. static_assert(sizeof(Carbon::C) == 12);
  22. static_assert(alignof(Carbon::C) == 4);
  23. ''';
  24. // --- packed.carbon
  25. library "[[@TEST_NAME]]";
  26. import Cpp;
  27. class C {
  28. var a: i32*;
  29. var b: i32;
  30. }
  31. class D {
  32. var c: C;
  33. var d: i32;
  34. }
  35. inline Cpp '''c++
  36. static_assert(sizeof(Carbon::C) == 12);
  37. static_assert(alignof(Carbon::C) == 8);
  38. static_assert(sizeof(Carbon::D) == 16);
  39. static_assert(alignof(Carbon::D) == 8);
  40. ''';