[clang-tidy] Add new check `modernize-use-structured-binding` (#158462)
This check detect code which can be transfered to c++17 structured
binding, and provides fix-it.
Limitations:
1. Ignore variables with attributes or qualifiers except `const` and `&`
since it's not very common:
```
static auto pair = getPair(); // no warning from this check
static int b = pair.first;
static int c = pair.second;
```
2. Some possibly convertable case:
(1)
```
const auto& results = mapping.try_emplace("hello!");
const iterator& it = results.first;
bool succeed = results.second;
// No change for succeed
```
In theory this can be transfered to structured binding:
```
const auto& [it, succeed] = mapping.try_emplace("hello!");
```
But it's needed to check whether `succeed` is changed after definition.
(2)
```
const auto results = mapping.try_emplace("hello!");
if (results.second) {
handle_inserted(results.first);
}
// no name deduced
```
That's not checked too.
It's coming from #138735, but leaves some unhanlded cases mentioned
above.
---------
Co-authored-by: Baranov Victor <bar.victor.2002@gmail.com>
Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
Co-authored-by: Congcong Cai <congcongcai0907@163.com>
Co-authored-by: Victor Chernyakin <chernyakin.victor.j@outlook.com>Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.