Closed
Description
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
Metadata
Assignees
Labels
No labels
Activity