<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62387>62387</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-tidy: hicpp-use-emplace: False positive with incorrect fix
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kees-jan
      </td>
    </tr>
</table>

<pre>
    Consider the following code:
``` C++
#include <vector>

struct S
{
    int i;
 std::vector<int> is;
};

void f()
{
    std::vector<S> s;
 s.push_back({1,{}});
}
```
Check `hicpp-use-emplace` will suggest to use emplace:
``` console
[<source>:12:7: warning: use emplace_back instead of push_back [hicpp-use-emplace]](javascript:;)
 s.push_back({1,{}});
      ^~~~~~~~~~~~~~~~
      emplace_back(
1 warning generated.
```
This, to the best of my knowledge, is incorrect. `emplace_back` cannot be used to initialize a struct. [StackOverflow seems to concur](https://stackoverflow.com/questions/20603335/c11-emplace-back-and-push-back-syntax-with-struct).

The suggested fix is to replace that line with `s.emplace_back()` (no arguments). This is definitely incorrect. It results in a default constructed struct, as opposed to one matching the provided initializer.

[See this example on compiler explorer](https://godbolt.org/z/fb3eY8Gs9)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlMFz6rgPx_8ac9GECTYhcMgBaPnN77SHvsuedowtErfGzloOtO-wf_uOAvTBay-b8YTYsr-SPhLWRK4NiI2oNqJ6mughdzE1b4hUvOow2Uf70WxjIGcxQe4QDtH7eHahBRMtCrUW5ZMo12JRXgZshdzwuCxL5YLxg0UQantCk2MS6vlqHN-U02AyvFzX6utJAAAXMjihbiuULftT65vO1oUs1DM4-twk6qdf3-P7FJ2Fg5BLIVff-Pgq-sKSdOd22g_U_bXX5o1V6s1MyC1r1E885OrB-SONy3TboXkDsSg7Z_q-GAgLPPZeG2RgZ-c90NC2SBlyhIEQbu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