[clang-tools-extra] [clang-tidy] Add new check `modernize-use-structured-binding` (PR #158462)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 22 07:36:59 PDT 2025


flovent wrote:

I just find out we should do some special handing for direct inited pair type, like:

```
{
  std::pair<int, int> P{1, 1};
  int x = P.first;
  int y = P.second; 
}
  
{
  std::pair<int, int> P(1, 1);
  int x = P.first;
  int y = P.second;
}

{
  std::pair<int, int> P;
  int x = P.first;
  int y = P.second;
}
```

We will give a warning and fix-it, but obviously it will break compilation because we don't have pair type. Any ideas what we should do about them?

1. Just ignore them
2. Just warning and don't provide fix-it

This pattern doesn't seems common in real world and the pair should not be created in the first place, so i prefer to ignore them and avoid further matching work.


https://github.com/llvm/llvm-project/pull/158462


More information about the cfe-commits mailing list