<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/138732>138732</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] Check request: modernize-use-std-tie-to-decompose-result
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
denzor200
</td>
</tr>
</table>
<pre>
Needs a check that will find creations of a tuple-like which was assigned from a returned value. The check will show warning to change it to use `std::tie`.
Also the check will provide fix-it in the case when it's possible to deduce names for future "tied" variables.
BEFORE:
```
iterator it;
bool succeed;
const auto results = mapping.try_emplace("hello!"); // WARNING AND FIX-IT
it = results.first;
succeed = results.second; // deduced 'it' and 'succeed'
```
AFTER:
```
iterator it;
bool succeed;
std::tie(it, succeed) = mapping.try_emplace("hello!"); // use 'it' and 'succeed'
```
The check will respect original order of default constructors, copy constructors, and assignment operators for a not built-in type and will not provide a fix-it that will broke the order - only warning will be emited:
```
const auto results = mapping.try_emplace("hello!"); // WARNING
const iterator& it = results.first; // only copy constructor being called
// but with `std::tie` we would call default constructor, copy constructor and then assignment operator
const bool succeed = results.second;
```
Another example with a built-in type:
```
const auto pos = get_position(); // WARNING AND FIX-IT
const float x = pos.first;
const float y = pos.second;
```
Keep in mind that the check will not provide fix-it in the case when it's impossible to deduce names - just a warning would be enough:
```
const auto results = mapping.try_emplace("hello!"); // WARNING
if (results.second) {
handle_inserted(results.first);
}
// no name deduced
```
In the case when it's impossible to use `std::tie` no warning must be provided:
```
const auto results = mapping.try_emplace("hello!");
handle_inserted(results);
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VtFu4zYQ_Br6ZSFDpmNbfvCDcj4XQYEUOARo3wJKXFm8UKRKLuP4vr4gJSdx4lzvWpwQJJBE7s7ODCcS3qu9QdywxTVbbCciUGvdRqL5Zh3P80ll5XFziyg9CKhbrB-AWkFw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