<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/82512>82512</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
-Wpointer-bool-conversion misses an obvious case
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
r-barnes
</td>
</tr>
</table>
<pre>
The following pattern is often used to evaluate an expensive function only once, cache its result, and return that on subsequent calls.
```
int foo() {
static bool is_true = [](){ return expensive_helper_function; };
return is_true;
}
```
But this code is subtly wrong. It should be
```
static bool is_true = [](){ return expensive_helper_function; }(); // Note the parens!
```
In the bad case it looks as though the lambda is being evaluated to a pointer(?) and this is being evaluated always to `true` when it is assigned to `is_true`.
It feels as though `-Wpointer-bool-conversion` should flag this, but it does not ([godbolt](https://godbolt.org/z/v9qhze9e3)).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVE2P6zYM_DXyhUjgyLFjH3x4aRBgLz0V6HEhWUysVhHzRCrpvl9fyEm6D8X2VsCAoY8hhzMDGWZ_joijaveqPVQmy0xpTCtrUkSuLLmP8bcZ4UQh0N3HM1yNCKYInoFOghEyowMhwJsJ2QiCiYB_XTGyvyGccpzEUwSK4QMoTqj0LzCZaUbwwpCQc5CyZ6KDhJJTBJmNAEXgbBm_Z4wCkwmB16o-qPqb6urntyx9FDgRKd0rPYDa7R_bAAAsRvwEliiA53dJGUE1B3iM-0Co3f7V9x_a7zOGK6b3F3vV7EHtDqp51v7s8EQ-i39e2B2-5LrPAjJ7hokcFg05WwkfcE8Uz2t4E-CZcnBg8Uv8_z3QA1AW-qj0EX4lQZAZ4WoSRlZ68yWNt7hcssbBZLg4CYHoTwbDIDPl87ycB3OxzpQxLZbsvCKy5MXAlXwUTIVEcyzelQgs6nyBMOFuPrgAVVcvWnc13GeMpbkvnZcou-eNlyFdvf7ZsjeBE2L4majq6tXvTyqrIuxqonjDxEWmrn4ZcgrmvJArWbVZSltHyBBJoIzQ7s_kLAV5GDGLXFk13x7CPo_WlM5KH38ofbwN3-cfOGBTDNDDunJj44ZmMBWOm13dt82u7dtqHluHFk1nsHF2cs0w2L7HVncd2rrvm7ryo671ttZ6s9ltO63Xm77v2um07YbddquNU9saL8aHdQi3S6FQeeaMY6_bja6CsRh4eQG0jniH5VBpXR6ENBbMyuYzq20dPAt_VhEvAcf_FA8unhm5vAdkb54yL2Gpcgrjv9TxMme7nuii9LGUf_5W10R_4CRKHxdSrPRxIf13AAAA__-4L4Eg">