<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57775>57775</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[[clang::set_typestate(consumed)]] is ignored after if statement
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
IhorGarbuzKh
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/Y89M95zGT
```
struct [[clang::consumable(consumed)]] Ptr
{
int id_ {};
[[clang::set_typestate(unconsumed)]]
void operator=( int in_id ) { id_ = in_id; }
[[clang::test_typestate(unconsumed)]]
operator bool() const { return id_; }
[[clang::set_typestate(consumed)]]
void reset() { id_ = 0; }
[[clang::callable_when(unconsumed)]]
void foo() {}
};
static void foo( Ptr in_ptr ) {
if( !in_ptr )
in_ptr = 1;
in_ptr.reset();
in_ptr.foo();
}
int main() {
}
```
No warnings here, but without the if statement i got one:
https://godbolt.org/z/9cE8aPTez
```
struct [[clang::consumable(consumed)]] Ptr
{
int id_ {};
[[clang::set_typestate(unconsumed)]]
void operator=( int in_id ) { id_ = in_id; }
[[clang::test_typestate(unconsumed)]]
operator bool() const { return id_; }
[[clang::set_typestate(consumed)]]
void reset() { id_ = 0; }
[[clang::callable_when(unconsumed)]]
void foo() {}
};
static void foo( Ptr in_ptr ) {
in_ptr = 1;
in_ptr.reset();
in_ptr.foo();
}
int main() {
}
```
<source>:21:12: warning: invalid invocation of method 'foo' on object 'in_ptr' while it is in the 'consumed' state [-Wconsumed]
in_ptr.foo();
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztVltr2zAU_jX2i2iwpfj24Ie06coYG30ojD0FWVJsD0UKktzQ_Pod2fHspGXNnsagRtHlnCOd71xJpflL2Ti3twFZBfgTjFrzSku30KaG0xF-P_Lia5EcH56CaB1Eq9OcRqfRH60zHXMoSG5hMElV7R8kK6aV7Xa0kiLA-XAQPMBFkKxhoEdnTs9lt8MGwdcqh1q-QZ6YrQMyY_3pm6RewbDCbdzLXlhHnUfSqVdYptvPuuVI74WhTpuArEF-gKQ2wIALHtgAkKwHKmBEHurMQW_icIDgeiAjBlRpLUHYq_birgdghOuM8jiu1X7phfd8YATcOOmdmxxdq5BRKX3sN4dGqKvcvtV6UjipmGXBmG_UtWx-x-eSD8YelvH-lFFbLxHgeBI4z6mRDtbFF6om9mLmkLOsPLF_g59eOHeSz6IdbdXMxAux86oa5m8aHahRraotaoSByN2hqnPo0LpGw-oaAQaiPqo74RMV1dohrYSPwuyh9wq9YPc5fXwSx49C_yj0_7TQ36rjf17BAbmzujMMCvIevIUB2irGMI2F7beteqYSrIRVMzBaK6S3aCegyH0yZj22DHly9VP4GsTZANuTD00roQ1A8lp4oe8JQJ6ikA39wYfu5vtv8jwsb7ggFGWcpoRExZLkIS8JL0hBQ9c6Kcq_z7oeW620ERzRrRPmrG2FnZGX_0Wgw3XVgukdHKR8HpebvdHeBXBsre2EhU2SZVkSNiUTIokwI5wsGV3yosj4MsFxyilPs5ylISSqkHaAvw7bEkcYR0WcRikmSb6gOcl4nGKRUIaXCQ2WkYCIy4VX7JtlaMoeQ9XVFpiytc5OTGotmCjE-D7tIH6m_AzTAzVVd_zShD3msgf8C7iCqZU">