[clang-tools-extra] [clang-tidy] Fix bug in modernize-use-emplace (PR #66169)

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 13 00:34:33 PDT 2023


================
@@ -1332,6 +1337,17 @@ void testBracedInitTemporaries() {
   v3.push_back(NonTrivialWithCtor{{}});
   v3.push_back({{0}});
   v3.push_back({{}});
+
+  std::vector<NonTrivialWithIntAndVector> v4;
+
+  // These should not be noticed or fixed; after the correction, the code won't
+  // compile.
+  v4.push_back(NonTrivialWithIntAndVector{1, {}});
+  // CHECK-FIXES: v4.push_back(NonTrivialWithIntAndVector{1, {}});
+  v4.push_back(NonTrivialWithIntAndVector{});
+  // CHECK-FIXES: v4.push_back(NonTrivialWithIntAndVector{});
+  v4.push_back({});
----------------
PiotrZSL wrote:

Would be good to check if zero-initialization is involved, if it is, then it's may not be safe to change this into emplace_back as default constructor may not initialize members of class, when `{}` will zero them.

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


More information about the cfe-commits mailing list