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

    <tr>
        <th>Summary</th>
        <td>
            Incorrect definition of `wcsstr` for older glibc depending on include order
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++
      </td>
    </tr>

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

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

<pre>
    This snippet fails to compile, as expected:
```c++
#include <cwchar>
#include <iosfwd>
void func() {
  wchar_t* v1;
  const wchar_t* cv2 = L"/";
  v1 = wcsstr(cv2, L"/"); // expected-error {{assigning to 'wchar_t *' from 'const wchar_t *' discards qualifiers}}
}
```

D148542 adds another path to including the system `wchar.h` without defining `__CORRECT_ISO_CPP_WCHAR_H_PROTO` as we do elsewhere, and older versions of glibc did not declare `__CORRECT_ISO_CPP_WCHAR_H_PROTO` for itself correctly when clang is the host compiler. In that situation, changing the include order causes it to unexpectedly compile:

```c++
#include <iosfwd>  // This and the next line are the only differences
#include <cwchar>
void func() {
 wchar_t* v1;
  const wchar_t* cv2 = L"/";
  v1 = wcsstr(cv2, L"/"); // Unexpectedly no error here
}
```

D150015 fixes this.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVNGO6yYQ_Rr8MrqRjWPHefBDNrnRXanSrrZb9TEiMI6pCLgMTjZ_X4Gd3L1SK-1bJeSEGWDOHM5BEOmTRWxZ9cQ49-MweJR9YJyzapeJMfTOt49wdnTq1r73moCsHgYM0AltCIID6c6DNsj4FgQBfgwoAypWbli-Y_mG1fk0JONPcUxRXmorzagQWLmVV9kLz8rv_5bUjrqreiQvTivoRisZbxhfA1vNRwKkUw6B8Q1cClY-4tJZCp-z8sKBlTv4LbbL9_H7c_WlSLmrJAqe8UZeeOzt01q-ZuUTpMn-0fA39N75BGf1NNGr7SkSxPhqrg2MbxhfQefdOYZ_AXZPKk1SeEXw9yiM7jR6YqtdHBM5jz93Yudp-u6KZVMtOQilCIR1oUcPgwh9BDKRmlD1CHSjgGdgdZ4ALHpW53DVoXdjAIWdTvhZnR8O25e3t-_b98Pz7y-H7evr4c_tj83b4cfh9e3l_SVuEwRXBOUADeG1Rz_JwSpwRqGHC3rSzhK4Dk5GHyUorcC6WEga4fGLdTrnQQdC04F03qMM5gbXHi1II-wJNKXWekfhrku_gGcLoRcBSIdRBO1sBCd7YU93Lu5ycz6ilWIkJNAhkjba-w2b20PrD3F_WeIPFcNdOMlNkaIIwOJHAKMtQiQjRpw1N1C669CjlUhf8M1_W-N_ccYfn5mzDiaDJHF8SclVnhcVdPoD461qWmSqLdW6XIsM26JuylXZ8KbO-pavy_KIhcCVWvOqPhaiUU29FkXeLbERy0y3POdlXhV5scqXy3qhStlU1Zor2TUdrwRb5ngW2iyMuZwXzp8yTTRiW_O6bDIjjmhofiujfOd7nh5L38ZN347jidgyN5oC_Twm6GCwfbazXGdjRRFGLyTzJTZncU92mS2CA9pkV2d_VWg2etP2IQwUlZjYPunQj8eFdGfG97H6_PNt8O4vlIHxfeqIGN-npv4JAAD__58p1fA">