[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

Zequan Wu via cfe-commits cfe-commits at lists.llvm.org
Thu May 16 09:29:39 PDT 2024


ZequanWu wrote:

Here's a smaller repro of the `-Wuninitialized` warning:
```
int TestBody_got;
namespace std {
template <int __v> struct integral_constant {
  static const int value = __v;
};
template <bool, class _Tp> using enable_if_t = _Tp;
template <class> class initializer_list {};
template <typename, typename>
constexpr bool IsTypeOrDerived = integral_constant<__is_same(int, int)>::value;
template <bool CONDITION, typename T>
using EnableIf = enable_if_t<CONDITION, T>;
template <typename T, typename BASE>
using EnableIfIsType = EnableIf<IsTypeOrDerived<T, BASE>, T>;
template <int> class Vector {
public:
  Vector(initializer_list<int>);
};
template <typename... Ts> Vector(Ts...) -> Vector<sizeof...(Ts)>;
class ProgramBuilder {
public:
  template <typename T, typename ARGS> EnableIfIsType<T, int> *create(ARGS);
};
using TestHelper = ProgramBuilder;
struct TypeTest : TestHelper {
  int *str_f16 = create<int>(Vector{0});
  TypeTest() {}
};
class TypeTest_Element_Test : TypeTest {
  void TestBody();
};
}
void std::TypeTest_Element_Test::TestBody() {
  int *expect = str_f16;
  &TestBody_got != expect;
}
$ clang reduce.cpp -std=c++20 -fsyntax-only -Wuninitialized -Wno-unused-comparison
reduce.cpp:34:20: warning: variable 'expect' is uninitialized when used here [-Wuninitialized]
   34 |   &TestBody_got != expect;
      |                    ^~~~~~
reduce.cpp:33:14: note: initialize the variable 'expect' to silence this warning
   33 |   int *expect = str_f16;
      |              ^
      |               = nullptr
1 warning generated.
```

Can you verify if this is a false positive or not? If it's a false positive and would take a while to fix, can you revert this commit?

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


More information about the cfe-commits mailing list