<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi everyone,</p>
<p>just decided to start playing around with -Wlifetime on Godbolt,
and came up with<br>
an example that failed to meet my expectations, namely:</p>
<div style="color: #000000;background-color: #fffffe;font-family:
Consolas, ">
<div><span style="color: #0000ff;">char</span><span style="color:
#000000;"> *leak()</span></div>
<div><span style="color: #000000;">{</span><span style="color:
#000000;"></span><span style="color: #0000ff;"><br>
</span></div>
<div><span style="color: #000000;"> </span><span style="color:
#0000ff;">return</span><span style="color: #000000;"> </span><span
style="color: #0000ff;">new</span><span style="color:
#000000;"> </span><span style="color: #0000ff;">char</span><span
style="color: #000000;">;</span></div>
<div><span style="color: #000000;">}</span></div>
<br>
<div><span style="color: #0000ff;">int</span><span style="color:
#000000;"> main()</span></div>
<div><span style="color: #000000;">{</span></div>
<div><span style="color: #000000;"> </span><span style="color:
#0000ff;">char</span><span style="color: #000000;"> *ch =
leak();</span></div>
<div><span style="color: #000000;">}</span></div>
<div><span style="color: #000000;"><br>
</span></div>
<div><span style="color: #000000;">Shouldn't the lifetime static
analyser complain that ch on main() leaks, or am I expecting
too much from the analyser?</span></div>
<div><span style="color: #000000;"><br>
</span></div>
<div><span style="color: #000000;">Initially I though that by
using main(), the analyser just assumed it would be released
anyway, but renaming it to something<br>
else, still doesn't trigger a leak warning.</span></div>
<div><span style="color: #000000;"><br>
</span></div>
<div><span style="color: #000000;">Thanks in advance,</span></div>
<div><span style="color: #000000;">Paulo<br>
</span></div>
</div>
</body>
</html>