Issue 82970
Summary clang-tidy: cppcoreguidelines-prefer-member-initializer doesn't understand structured binding
Labels clang-tidy
Assignees
Reporter FalcoGer
    Consider this code:

```c++
#include <tuple>
class C
{
 private:
    int m_data1;
    double m_data2;

  public:
 C(const float f)
    {
        auto [i, d] = Create(f);
 m_data1     = i;
//      ~~~~~~~~~~~~~~~~
//      'm_data1' should be initialized in a member initializer of the constructor (fix available) (clang-tidy cppcoreguidelines-prefer-member-initializer)
        m_data2 = d;
//      ~~~~~~~~~~~~~~~~
//      'm_data2' should be initialized in a member initializer of the constructor (fix available) (clang-tidy cppcoreguidelines-prefer-member-initializer)
    }

    static auto Create(const float f) -> std::tuple<int, double>
    {
        return {static_cast<int>(f), static_cast<double>(f)};
    }
};

auto main() -> int
{
    const float MAGIC = 3.1415F;
    C c(MAGIC);
 return 0;
}
```

clang tidy flags those members as being able to be done through the initializer list. however that is not true. when applying the quick fix, it will produce something like this:

```c++
    C(const float f) : m_data1(i), m_data2(d)
 {
        auto [i, d] = Create(f);
    }
```

Which of course is invalid.

current version:

```text
Ubuntu LLVM version 19.0.0
  Optimized build.
```

from

```text
Ubuntu clang version 19.0.0 (++20240222031214+307409a8872f-1~exp1~20240222151237.1514)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to