Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting "Warning: Cannot prove that 'result' is initialized" for an importcpp'd proc with var T return type #14314

Closed
kaushalmodi opened this issue May 12, 2020 · 0 comments · Fixed by #14319

Comments

@kaushalmodi
Copy link
Contributor

I need to add a trailing = to proc declarations for the functions I importcpp from std::vector, if I want to use runnableExamples. But if I do so, I get this warning if the return type is var T.

Warning: Cannot prove that 'result' is initialized. This will become a compile time error in the future. [ProveInit]

Example

Save below file to a t.nim and run nim doc --backend:cpp t.nim (requires the latest nim devel version).

{.push header: "<vector>".}

type
  Vector*[T] {.importcpp: "std::vector".} = object

proc newVector*[T](): Vector[T] {.importcpp: "std::vector<'*0>()", constructor.}

proc add*[T](v: var Vector[T], elem: T){.importcpp: "#.push_back(#)".}

proc first*[T](v: Vector[T]): var T {.importcpp: "front".} =
  ## Return the reference to the first element of the Vector.
  ##
  ## This has an alias proc `front`.
  ##
  ## https://en.cppreference.com/w/cpp/container/vector/front
  runnableExamples:
    var
      v = newVector[int]()
    v.add(100)
    doAssert v.first() == 100

{.pop.}

Current Output

The doc gets generated fine, but we get this warning:

/home/kmodi/sandbox/nim/bug_reports/cannot_prove_result_uninit/t.nim(11, 3) Warning: Cannot prove that 'result' is initialized. This will become a compile time error in the future. [ProveInit]

Expected Output

No ProveInit warning

Additional Information

$ nim -v
Nim Compiler Version 1.3.3 [Linux: amd64]
Compiled at 2020-05-11
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 86669ef5b4c9711d81e961c2f68a05aa4f4d9ece
active boot switches: -d:release

/cc @timotheecour

@kaushalmodi kaushalmodi changed the title Getting "Warning: Cannot prove that 'result' is initialized" for an importcpp'd proc Getting "Warning: Cannot prove that 'result' is initialized" for an importcpp'd proc with var T return type May 12, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue May 12, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant