<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/133114>133114</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] Check request: modernize-use-std-quoted
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
denzor200
</td>
</tr>
</table>
<pre>
Needs a check that will find string literals that are written to a stream with quotes and will suggest to change the code with `std::quoted` usage.
BEFORE:
```
constexpr const char line[] = "The first line";
constexpr const char line2[] = "Stays \" unchanged";
const std::string line3 = get_string();
ss << '"' << line << '"';
ss << '"' << line2 << '"';
ss << '"' << line3 << '"';
ss << "\"Hello world!\"" << std::endl;
```
AFTER:
```
constexpr const char line[] = "The first line";
constexpr const char line2[] = "Stays \" unchanged";
const std::string line3 = get_string();
ss << std::quoted(line);
ss << '"' << line2 << '"'; // due to the `"` symbol in the middle of `line2`
ss << '"' << line3 << '"'; // not a literal
ss << std::quoted("Hello world!") << std::endl;
```
I suppose this check should provide an option to switch it to "unsafe" mode(This is the mode when change suggests for even not a string literal).
AFTER(UNSAFE-MODE):
```
constexpr const char line[] = "The first line";
constexpr const char line2[] = "Stays \" unchanged";
const std::string line3 = get_string();
ss << std::quoted(line);
ss << std::quoted(line2); // OK, but unsafe because `line2` contains `"` symbol
ss << std::quoted(line3); // OK, but unsage because `line3` not a literal
ss << std::quoted("Hello world!") << std::endl;
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkVk1v4zYQ_TXUZWCDHvojOuig-AMtim6A3fRc0OJYYkuTXg4VN_vrC0p2mjSLrbGHHlrAgAVy3hvNzJsHaWbbeqJKLO7FYlPoPnUhVob8lxBRymIfzHMlZP2ByDBoaDpqfofU6QRn6xwcrDfAKVrfgrOJonY8XutIcI42JfKQAugcRfoIZ5s6-NyHRAzam5GG-7YlTjmw6bRvCVJH0ARDY7xYSk5GqFqoesAasZTQs25pKmQtZH2_3T183OYIWYulvPxk3QTPif44RRieMn0EZz2NFYNQGxCIjx3BwUZO4x2iUPffQuNb-KeknxnEYi0QofdjDeYtDbxU8NIvT2pgaCn9Oh4KvBNYjihmEGot1BoErjIXrq4HGfru8iYUfh9M3QDDsf4fyLkA5xCdETgbz3JbLnEvXSBv3Ejyel5C1vXucfvxPzrJv6sY78a3vG3kXx0eCNwJ3IHpKe9PXpzcMMS8Ivx83AcH1g_nR2uMIwiHHDEWP7T2e4Z_TetDAn3d_X-o9b06Mlt5uzR-BO5Pp8DZHyxf3Ii70DsDpxierCHQHsIp2TDYDp9tajqwg7UIxN6zPmRVwDEYEnj3mHksj-0Z_KYjfzWhiy0xHEIEeiJ_qfat4Qksp6-Vi3e_fPhU77aTnx8222G0_28pfz0Qx8irjB5-EriGfZ9gHBHsqdE902ul5nqTtp7fCfyGfOpb-dp3-VQm__e0XZhKmVKVuqBqtporKZdSzYuuIrXQaraXzaKcL_VitWy0nqMq5WFlZnJJha1Q4kIqXM6WKNV8auayWah9ebgrV7MSUcwlHbV1U-eejtMQ28Iy91TNlJrN5oXTe3I8fAAgNk77dpKseR7sfFPEKqMm-75lMZfOcuK_eJJNbvh0eAVbbGA9bGWkzz1xEqoe9ip6-4UmPdOEk5mMXSv66KoupRPn1gxzaW3q-v20CUeBu5zo8jc5xfAbNUngbnh7Fri7FPBU4Z8BAAD__2UAkIw">