constexpr.carbon 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/full.carbon
  6. // EXTRA-ARGS: --clang-arg=--std=c++20
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/var/constexpr.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/var/constexpr.carbon
  13. // --- bool.carbon
  14. library "[[@TEST_NAME]]";
  15. import Cpp inline '''
  16. constexpr bool b = true;
  17. ''';
  18. class C(B:! bool) {}
  19. fn F() -> C(Cpp.b);
  20. let x: C(true) = F();
  21. // --- int.carbon
  22. library "[[@TEST_NAME]]";
  23. import Cpp inline '''
  24. constexpr int i = 123;
  25. ''';
  26. class C(I:! i32) {}
  27. fn F() -> C(Cpp.i);
  28. let x: C(123) = F();
  29. // --- float.carbon
  30. library "[[@TEST_NAME]]";
  31. import Cpp inline '''
  32. constexpr float flt = 123.5;
  33. ''';
  34. class C(V:! f32) {}
  35. fn F() -> C(Cpp.flt);
  36. let x: C(123.5) = F();
  37. // --- pointer.carbon
  38. library "[[@TEST_NAME]]";
  39. import Cpp inline '''
  40. int i = 123;
  41. constexpr int* _Nonnull ptr = &i;
  42. ''';
  43. class C(V:! i32*) {}
  44. fn F() -> C(Cpp.ptr);
  45. let x: C(&Cpp.i) = F();