torc.nim 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. discard """
  2. targets: "cpp"
  3. matrix: "--gc:orc"
  4. """
  5. import std/options
  6. # bug #18410
  7. type
  8. O = object of RootObj
  9. val: pointer
  10. proc p(): Option[O] = none(O)
  11. doAssert $p() == "none(O)"
  12. # bug #17351
  13. type
  14. Foo = object of RootObj
  15. Foo2 = object of Foo
  16. Bar = object
  17. x: Foo2
  18. var b = Bar()
  19. discard b
  20. # bug #4678
  21. {.emit: """/*TYPESECTION*/
  22. enum class SomeEnum {A,B,C};
  23. """.}
  24. type
  25. EnumVector[T: enum] {.importcpp: "std::vector", header: "vector".} = object
  26. SomeEnum {.importcpp, nodecl.} = enum
  27. A,B,C
  28. proc asVector*[T](t: T): EnumVector[T] =
  29. discard
  30. # Nim generates this signature here:
  31. # N_NIMCALL(std::vector<> , asvector_106028_3197418230)(SomeEnum t0)
  32. discard asVector(SomeEnum.A)
  33. block: # bug #10219
  34. type
  35. Vector[T] {.importcpp: "std::vector", header: "vector".} = object
  36. proc initVector[T](n: csize_t): Vector[T]
  37. {.importcpp: "std::vector<'*0>(@)", header: "vector".}
  38. proc unsafeIndex[T](this: var Vector[T], i: csize_t): var T
  39. {.importcpp: "#[#]", header: "vector".}
  40. proc `[]`[T](this: var Vector[T], i: Natural): var T {.inline, noinit.} =
  41. when compileOption("boundChecks"):
  42. # this.checkIndex i
  43. discard
  44. result = this.unsafeIndex(csize_t(i))
  45. var v1 = initVector[int](10)
  46. doAssert v1[0] == 0
  47. block: # bug #12703 bug #19588
  48. type
  49. cstringConstImpl {.importc:"const char*".} = cstring
  50. constChar = distinct cstringConstImpl
  51. {.emit: """
  52. const char* foo() {
  53. return "hello";
  54. }
  55. """.}
  56. proc foo(): constChar {.importcpp.} # change to importcpp for C++ backend
  57. doAssert $(foo().cstring) == "hello"