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

    <tr>
        <th>Summary</th>
        <td>
            libc++ requires `mbstate_t` even when we disable support for wide characters
        </td>
    </tr>

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

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

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

<pre>
    Even when we disable support for wide characters with `_LIBCPP_HAS_NO_WIDE_CHARACTERS`, libc++ still requires the definition of `mbstate_t`.

```
In file included from /llvm_libcxx/include/algorithm:1955:
In file included from /llvm_libcxx/include/__algorithm/ranges_sample.h:13:
In file included from /llvm_libcxx/include/__algorithm/sample.h:18:
In file included from /llvm_libcxx/include/__random/uniform_int_distribution.h:20:
In file included from /llvm_libcxx/include/iosfwd:117: 
In file included from /llvm_libcxx/include/__std_mbstate_t.h:14:
/llvm_libcxx/include/__mbstate_t.h:51:4: error: "We don't know how to get the definition of mbstate_t without <wchar.h> on your platform."
   51 | #  error "We don't know how to get the definition of mbstate_t without <wchar.h> on your platform."
      | ^ 
In file included from /llvm_libcxx/include/algorithm:1955: 
In file included from /llvm_libcxx/include/__algorithm/ranges_sample.h:13: 
In file included from /llvm_libcxx/include/__algorithm/sample.h:18: 
In file included from /llvm_libcxx/include/__random/uniform_int_distribution.h:20: 
/llvm_libcxx/include/iosfwd:135:14: error: reference to unresolved using declaration 
  135 | typedef fpos<mbstate_t> streampos; 
      |              ^ 
/llvm_libcxx/include/__std_mbstate_t.h:25:1: note: using declaration annotated with 'using_if_exists' here 
 25 | using ::mbstate_t _LIBCPP_USING_IF_EXISTS; 
      | ^
```

The workaround used by [some of the platforms](https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/kernel/lib/ktl/include-after/wchar.h;l=19) is to define an empty `mbstate_t`, but ideally this shouldn't be needed at all.

This is related to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