<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54076>54076</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] readability-container-data-pointer suggests incorrect replacement for std::string
</td>
</tr>
<tr>
<th>Labels</th>
<td>
bug,
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
carlosgalvezp
</td>
</tr>
</table>
<pre>
Hi,
The `readability-container-data-pointer` suggests a replacement that makes code not compile when using `std::string` in C++ < 17, due to the fact that `data()` only returns a `char const*`, i.e. there's no non-`const` overload:
```cpp
int main()
{
std::string s = "foo";
char* s_ptr = &s[0];
}
```
https://godbolt.org/z/3rnsjrxKE
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyFUkuP2yAQ_jX4gmx5wY_44EMerSr12nuFzcRml4AF47TZX9_B2XajXGqNgRmGb755DF7f-m-GiSMrT6zc39cfM3DWlAGUVoOxBm_56B0q4yDkWqHKF28cQiAnHtdpgoiRKx5gsWqECzjkOCvkF_UGkY9eA3ce6XBZjAX-awbH12jclMJE1EzuSSIGMiVM4_iRiQMJZ_LIX1oiyPUKHD0BAz-r8SMCeSdCTOyY6NJT7-yNiOAaXKJEpnFWgUK7iEzsSU9YpoAiIQVgoo1EjsTlyXnzSzhXCNarjdpDadL7TcZluVuoEJSncR8U7l7t4X7g9D3lxyPldOJMiLP3tDL54Ju4Eksefy4YPvyayOpDyerTP0_Wnp7YPFKcEZeYIoqvJJPXg7dY-DCR9k6_pMq8ht_fv2S6l7qTncrQoIWewoxWuSlHo28Uj_9_AD67b9zoQwDqy-MUnH14zj9bg-2fOBqc16Gg8SDF2uvfLV-CfyVIUk2MK0Q61FXZNtncg9x1atfsdkLqUpSirVpR0TrW-qWWuyazagAbU1JU5GGdUqmp87Q9JEm2-pSZngCS1GUnG1kVA4AcO6mbsms6NVSsKoF6bIvEKpUyC_1GkHAjXVpDJfi8VDGaycFW0YSvVpx96EdFExUnZa_wvmRbRv2Wzh8WfxQR">