[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


================
@@ -207,11 +211,13 @@ void UseEmplaceCheck::registerMatchers(MatchFinder *Finder) {
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
   // allow for T{} to be replaced, even if no CTOR is declared
-  auto HasConstructInitListExpr = has(initListExpr(anyOf(
-      allOf(has(SoughtConstructExpr),
-            has(cxxConstructExpr(argumentCountIs(0)))),
-      has(cxxBindTemporaryExpr(has(SoughtConstructExpr),
-                               has(cxxConstructExpr(argumentCountIs(0))))))));
+  auto HasConstructInitListExpr =
+      has(initListExpr(anyOf(initCountIs(0), initCountIs(1)),
----------------
PiotrZSL wrote:

`initCountIs(1)` will work only if we got constructor that take that argument.

```
#include <vector>

struct test { int a; };

int main()
{
    std::vector<test> aa;
    aa.emplace_back(1);

    return 0;
}
```

Code like this does not compile.

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


More information about the cfe-commits mailing list