constexpr.carbon 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. //
  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/constexpr.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/constexpr.carbon
  12. // --- bool.carbon
  13. library "[[@TEST_NAME]]";
  14. import Cpp inline '''
  15. constexpr bool b = true;
  16. ''';
  17. class C(B:! bool) {}
  18. fn F() -> C(Cpp.b);
  19. let x: C(true) = F();
  20. // --- int.carbon
  21. library "[[@TEST_NAME]]";
  22. import Cpp inline '''
  23. constexpr int i = 123;
  24. ''';
  25. class C(I:! i32) {}
  26. fn F() -> C(Cpp.i);
  27. let x: C(123) = F();
  28. // --- float.carbon
  29. library "[[@TEST_NAME]]";
  30. import Cpp inline '''
  31. constexpr float flt = 123.5;
  32. ''';
  33. class C(V:! f32) {}
  34. fn F() -> C(Cpp.flt);
  35. let x: C(123.5) = F();