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

    <tr>
        <th>Summary</th>
        <td>
            libc++ `char_traits.h` assumes `EOF` is always available
        </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>
    libc++ assumes that `EOF` is always available and uses it unconditionally in the `char_traits.h` implementation.
```
In file included from /llvm_libcxx/include/chrono:830: 
In file included from /llvm_libcxx/include/__chrono/convert_to_tm.h:22: 
In file included from /llvm_libcxx/include/__chrono/statically_widen.h:17: 
In file included from /llvm_libcxx/include/__format/concepts.h:17: 
In file included from /llvm_libcxx/include/__format/format_parse_context.h:16: 
In file included from /llvm_libcxx/include/string_view:225: 
/llvm_libcxx/include/__string/char_traits.h:169:100: error: use of undeclared identifier 'EOF' 
  169 |   static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT { return int_type(EOF); } 
      | ^ 
/llvm_libcxx/include/__string/char_traits.h:169:66: error: no return statement in constexpr function 
 169 |   static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT { return int_type(EOF); }
```
LLVM libc doesn't currently define `EOF` on baremetal targets because there's no filesystem support (since baremetal targets typically don't have filesystem to begin with) which results in a compiler error.

We could extend LLVM libc to define `EOF` even on baremetal targets, but it's an open question whether libc++ should be able to handle the case where `EOF` is undefined.

This is related to issue https://github.com/llvm/llvm-project/issues/84879.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVV1v4jgU_TXm5WpR4hASHngoFLSVZqbVbLU7b5FjX7B3HTtr30D59ysHWlptNQ_bSotQCIl97jnH90PEaPYOccnKFStvJ2Ig7cOyRwraR_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