Issue |
138732
|
Summary |
[clang-tidy] Check request: modernize-use-std-tie-to-decompose-result
|
Labels |
clang-tidy
|
Assignees |
|
Reporter |
denzor200
|
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);
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs