<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/155752>155752</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
std::print() can unexpectedly clobber errno
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
m2
</td>
</tr>
</table>
<pre>
print() invokes __vprint_unicode() invokes __is_terminal() invokes isatty(), which is subject to clobbering errno with ENOTTY when not writing to a terminal.
C++23 working draft in ยง31.7.10 bullet 7 specifies logic (flushing, etc.) conditional on stream referring to a terminal and use of isatty() specifically, so invocation of isatty() is motivated.
For the case of logging with print() between a system call and logic checking errno (e.g. differentiating EAGAIN from other errors), this leads to a hassle diagnosing mysterious ENOTTY errors.
I couldn't find anything in the standard about expectations for this and maybe there's a good reason not to, but I'd propose a store/restore of errno around the isatty() call would avoid frustration. Otherwise the same thing has to be done in any use of print() not wanting errno to be affected.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxkVM1yozgQfhr50jUUiBDsAwcnO97KZeYylz2lGqkBbYTkUjf2-u23BHElMzlBqf--n65GZjcGok41T6r5a4eLTDF1s9710d66c3JBlN4rfQAXLvGNGF5fL-vz6xKciZa-hB2_CqXZBfR_xByjyG17VPoZrpMzEzgGXvp_yQhIBONj31NyYQRKKUS4Opng-4-fv379A9eJAoQocE1OcopEQLhPK1R5VOXxWeknpZ90DdeY3nKWTTgIuADqWatjW1dFW1Ql9Iv3JNACn8m4wRGDj6MzoPR-8AtPLowZJokpMg0Tg3XiYkAPMQBLIpwh0UApfQEDGCwsTBCH33jfhxn0_pa7c1z1MZg7f8l2DHMUd0Eh-87vFBPIRGBw6-7jOObxq1CfHetJrkQBEPjGQjPkmSuujaaZyLx9CK30noqxAOuGgRIFcbhq_P349_HlBwwpzhBlopTzY-J3E2VyDJ7Q8ibAhMyewDocQ-TcYM7Tk4sL333cGrzzeQETF2-D0q3A4IIFDDfJ4mfLMlMWDBaTBezjIkD_ncnIqhfDsKrheOU1462nXJJI6ZYBYYzRQiLkuC2OxIy5XwRelG4tnFM8R6askcRcdUq0_mVlN10wxSXYFchv1qxqXjN0wEt0Foa0sKQVVwE_M4qrY9oY4Jx_MqcJV6F6AhsDZYoYbvdN-WzfuucY5MOhrQyHgUxeh53tanuoD7ijrmqbx7rZV_VhN3UP1mLbP1aHx7rB5uHQNwPWpip7XZdDj8POdbrUTbnX-7KpmvpQYFs2PVb7uiSztxWph5JmdL7w_jIXMY07x7xQVzVN2-idx548r0dD60BXWKNK63xDUpeLvvXLyOqh9I6FP9qIE08di1X1UdXHz3wNBljCZi5Zf7ufgo38bkm-m0TOnCv1SenT6GRa-sLEWelTnvD--XZOMZ8TpU8rLlb69A780un_AwAA__8IOq1R">