<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68886>68886</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] modernize-use-emplace suggests C++20 code under C++17
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
maflcko
</td>
</tr>
</table>
<pre>
Assuming a C++ file with:
```cpp
#include <vector>
struct Marker {
Marker();
};
struct Number {
int num;
Marker dummy;
};
int main() {
std::vector<Number> vec;
vec.emplace_back(Number{.num = 2});
// vec.emplace_back(2); // C++20
}
```
Clang Tidy will print:
```
[<source>:14:22: warning: unnecessary temporary object created while calling emplace_back [modernize-use-emplace]]
14 | vec.emplace_back(Number{.num = 2});
| ^~~~~~~~~~~~~~~~
1 warning generated.
```
This is wrong, when using C++17, because fixing the warning requires C++20.
Godbolt: https://godbolt.org/z/xn1Y3xMYo
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVD2T4jgQ_TXtpAvKkjDYgQM-hov2ok02upLlHls3sszpA4YN7rdfCczi2dqbYCkXiO5-_fz6dUl6rztLVEOxg-KQyRj60dWDfDXqbcyasb3WW-_joG2HEvfAd8B3-KoN4UWHHsQW8gPkj-91fn_U6TRFuNBWmdgSgtifSYXRgXiZg3xwUQX8It0bOYTN7h5GxCkGvARegZgSsDk8z_MOf8ah-bmDtgFtHH4Anl2xjcNw_aRrgg5S2zv9x7Y-tEm62D4U7e_kIF7wTOpJdya1pOFkpKK_GqnegJdT5Wa3tHFAEAfkiXymMDEAPwI__grP76WPiskTnj91fPRirmlvpO3wq26veNHG4MlpG_7PxOlvsQOx92N0ipJzYstWILacg9jiRTqrbZeO0VpS5L10Vww0nEaXTmPzN6mAypEM1OKlT5ujpDFpoebCEIrdMLbkrP5Oi-hpMWWhOKTnMRi2Qtjsf3-ueIND8fLvx8-9gj0UYUeWXHrn5Sfj_Nprj9rjxY22A77HS08Wo08NJl_YJsUbUjJ6wlf9nnKhpx9Ejv6J2pF_GrmcU_wxts1okkfYh3Dyyayb8d09sRxdB_z4Hfjx3bJv4v3Lt_GOzNpatJWoZEY1W1cbxooir7K-Los1SV5UrKnWhaxKUTQtI9moMi_ZumCZrnnOBcsZZ7woebUsNxsm22bVNKxVRbOCVU6D1GZpzHlIb5Bp7yPV67Is15mRDRl_u1I4V2njFkG3V-A8XTGuTqBFEzsPq9xoH_yzTdDB3C6jGaw44C8XA33sOvJhNjlUY0sYbUvuOf8sOlP_NDsd-tgs1TgAPyby6WdxcmPaV-DHmyAP_HjT9F8AAAD__6cNgf8">