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

    <tr>
        <th>Summary</th>
        <td>
            Clang static analyzer should complain when input/output functions violate stream orientation 
        </td>
    </tr>

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

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

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

<pre>
    On the libera IRC network, someone pointed out that the following only prints regular char or wide char output depending on which came first, such that only two lines will be printed for both versions:

```
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>

int main (const int argc, char * const * argv)
{
        if (setlocale (LC_ALL, "") == NULL)
 exit (EXIT_FAILURE);

        //puts   ( "The sky is falling."                   ); // Toggle this line to see what I mean.
 fputws (L"The sky is falling.\n"         , stdout);
        puts ( "The oceans are burning."               );
        fputws (L"The mountains are crumbling.\n", stdout);

        return EXIT_SUCCESS;
}```

This is due to the C standard:

http://www.iso-9899.info/n1570.html#7.21.2p4

```
 Each stream has an orientation. After a stream is associated with an external file, but
    before any operations are performed on it, the stream is without orientation. Once a wide
    character input/output function has been applied to a stream without orientation, the
    stream becomes a wide-oriented stream. Similarly, once a byte input/output function has
    been applied to a stream without orientation, the stream becomes a byte-oriented stream.
    Only a call to the freopen function or the fwide function can otherwise alter the
    orientation of a stream. (A successful call to freopen removes any orientation.)
```

Clang's static analyzer does not complain about this, when a check that catches this would be appreciated. Clang Tidy does not complain either.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVt9v2zgM_muUF6JGItdN_ZCHLm2AAsUNWDvg3gZapmPdZMmQ5Hq5v_5A2fmxNRtwhuFYosXv4yeSCoag95ZoI4pPonhc4BBb5zf-gG5Rufqw-WwhtgRGV-QRnr9swVIcnf8u5BaC68hZgt5pG6kGN0SILca0pHHGuFHbPThrDtB7bWMAT_vBoA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