lifetime issue: Bug or not?
schveiguy at gmail.com
Fri Nov 22 18:54:49 UTC 2019
I have code in my proprietary project that looks like this:
auto stmt = SQLStatement("`foo`"); // table
return stmt.where("`id` = ?", id);
where is a function that adds a where clause with a given value to the
SQL statement. It takes an SQLStatement by ref, and returns that
statement by ref.
Signature looks like this:
ref SQLStatement where(T)(return ref SQLStatement stmt, string clause, T
In this case, I'm using the convenience of returning the statement to
return that from the function.
However, the compiler is complaining:
Error: returning where(stmt, "`id` = ?", id) escapes a reference to
local variable stmt
But... it's not returning a ref. So why the complaint?
I have to separate into 2 lines.
I tried to make a simple example to show the problem, but looks like it
doesn't fail in that case.
More information about the Digitalmars-d