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

    <tr>
        <th>Summary</th>
        <td>
            False report modernize-return-braced-init-list with std::string and incorrect fix is applied
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          jackua22
      </td>
    </tr>
</table>

<pre>
    The issue is reproducible with clang 17 and 18.
This file
#include <string>
std::string space(size_t n) {
 return std::string(n, ' ');
}
generates a warning
warning: avoid repeating the return type from the declaration; use a braced initializer list instead [modernize-return-braced-init-list]
And with auto-fix, tidy modifies it with the following diff
<     return std::string(n, ' ');
---
>     return {n, ' '};
Then the compilation fails:
error: non-constant-expression cannot be narrowed from type 'size_t' (aka 'unsigned long') to 'char' in initializer list [-Wc++11-narrowing]

To reproduce:
clang-tidy '--checks=modernize-return-braced-init-list' --fix str.cpp -- -std=c++17 -stdlib=libc++
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVMFu4zgM_RrmQihw6KR2Dz40zeQLCuxxIUt0zKkiGZI8mfbrF7KT7u7sYbABktgUH8n3SFGnJBfP3MHhCIfTRs95DLH7rs37rIk2fbAf3dvIKCnN5RcjTzHY2UjvGG-SRzRO-wvuGtTe4q7dQnWC6uVtlISDOF5fgWrxxs2WEerXlKP4C9Tf1sOULdQvUL-sdkyTNgzUJvnkPzN6oGeE5rg6Y-Q8R4-_gIBaD_SKQE35Aj1DfUdAc1ofLuw56swJNd509AW2HDxe6hfUP4LYwpJ1LrXkkR8Z88fEOMRwXYyWjdNRZwke6iPOiVFjH7Vhi-Ili3byyRGdpIziU2ZtEQ7Ha7AcvXyyWsOqFaMKRhVnONzLffF2VVjPOahBfhZ-WewHXoOVQTih5NWjFDQE58Kt1GxlGO7U61csn_-tmVLqEeHbPyNAc_wXpDl9Qd5G9kshJlwncYsyOGhxqeRcXDjGEIvKPnhlgk9Z-6z45xQ5peJutPchY8_odYzhxvYueJEeqFknYk3e6nddbLNfZtiiC4VSoYE5lBMz6lh8xf-3I3A4qj8M0BHouNupNV3R5KH-nVT4mnj-orFMvFo6AdQoZUY27wnq0-97Sw2q0kpMOW7NNKFSqJa2nB7FNIvBSQ_1yUl_N29sV9vn-llvuNs1O6qI2ifajN2-ImMOtiKzt3bgqq763jz1ZOlpp21TbaSjivbVvqJqd9gTbTW3-1a3e7t76nvqD7Cv-KrFbZ37cd2GeNkst71rm7qqNk737NKyIIg839ZVAERlX8SuYFQ_XxLsq8Iw_R0lS3bcnbVL5QpNIWb8rUDrOP-6EMpmEW9CjGwyFvkkoZ4mJ2w3c3TdmPO0jBmdgc4XyePcb024Ap1LOfc_NcXwnU0GOi8kEtB5IflXAAAA__-nc5tN">