summaryrefslogtreecommitdiff
path: root/libcxx/include/fstream
AgeCommit message (Collapse)Author
2025-11-21[libc++] Revert fstream::read optimizations (#168894)Jordan Rupprecht
This causes various runtime failures, as reported in #168628. This reverts both #165223 and #167779
2025-11-13[libcxx] Fix xsgetn in basic_filebuf (#167779)Michael Jones
The optimized version of xsgetn for basic_filebuf added in #165223 has an issue where if the reads come from both the buffer and the filesystem it returns the wrong number of characters. This patch should address the issue.
2025-11-07[libc++] Optimize fstream::read (#165223)Nikolas Klauser
``` Benchmark old new Difference % Difference ----------- -------- -------- ------------ -------------- bm_read 2468.45 736.27 -1732.18 -70.17% ```
2025-10-09[libc++] Remove availability annotations that aren't required anymore (#161640)Nikolas Klauser
Apple dropped support for some older platforms, so we can also remove the annotations for them. See https://developer.apple.com/support/xcode/ for the supported versions.
2025-08-27[libc++] Optimize ofstream::write (#123337)Nikolas Klauser
``` ---------------------------- Benchmark old new ---------------------------- bm_write 1382 ns 521 ns ```
2025-07-17[libcxx][fstream][NFC] Make __failed helper lambda a member function (#149390)Michael Buch
This patch makes the `__failed` lambda a member function on `fstream`. This fixes two LLDB expression evaluation test failures that got introduced with https://github.com/llvm/llvm-project/pull/147389: ``` 16:22:51 ******************** 16:22:51 Unresolved Tests (2): 16:22:51 lldb-api :: commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py 16:22:51 lldb-api :: commands/expression/import-std-module/list/TestListFromStdModule.py ``` The expression evaluator is asserting in the Clang parser: ``` Assertion failed: (capture_size() == Class->capture_size() && "Wrong number of captures"), function LambdaExpr, file ExprCXX.cpp, line 1277. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. ``` Ideally we'd figure out why LLDB is falling over on this lambda. But to unblock CI for now, make this a member function. In the long run we should figure out the LLDB bug here so libc++ doesn't need to care about whether it uses lambdas like this or not.
2025-07-15[libc++] Ensure that we restore invariants in basic_filebuf::overflow (#147389)Louis Dionne
In rare circumstances, the invariants could fail to be restored.
2025-06-24[libc++] Refactor basic_filebuf::overflow() (#144793)Louis Dionne
Refactor the function to streamline the logic so it matches the specification in [filebuf.virtuals] more closely. In particular, avoid modifying the put area pointers when we loop around after a partial codecvt conversion. Note that we're technically not up-to-spec in this implementation, since the Standard says that we shouldn't try more than once after a partial codecvt conversion. However, this refactoring attempts not to change any functionality.
2025-06-17[libc++][NFC] Consistently qualify calls to C functions in <fstream> (#144539)Louis Dionne
2025-05-28Revert "[libc++] Introduce ABI sensitive areas to avoid requiring ↵James Y Knight
_LIBCPP_HIDE_FROM_ABI everywhere (#131156)" (#141756) This reverts commit c861fe8a71e64f3d2108c58147e7375cd9314521. Unfortunately, this use of hidden visibility attributes causes user-defined specializations of standard-library types to also be marked hidden by default, which is incorrect. See discussion thread on #131156. ...and also reverts the follow-up commits: Revert "[libc++] Add explicit ABI annotations to functions from the block runtime declared in <__functional/function.h> (#140592)" This reverts commit 3e4c9dc299c35155934688184319d391b298fff7. Revert "[libc++] Make ABI annotations explicit for windows-specific code (#140507)" This reverts commit f73287e623a6c2e4a3485832bc3e10860cd26eb5. Revert "[libc++][NFC] Replace a few "namespace std" with the correct macro (#140510)" This reverts commit 1d411f27c769a32cb22ce50b9dc4421e34fd40dd.
2025-05-18[libc++] Introduce ABI sensitive areas to avoid requiring ↵Nikolas Klauser
_LIBCPP_HIDE_FROM_ABI everywhere (#131156) This patch introduces `_LIBCPP_{BEGIN,END}_EXPLICIT_ABI_ANNOTATIONS`, which allow us to have implicit annotations for most functions, and just where it's not "hide_from_abi everything" we add explicit annotations. This allows us to drop the `_LIBCPP_HIDE_FROM_ABI` macro from most functions in libc++.
2025-04-09[libc++] Remove _LIBCPP_TEMPLATE_VIS (#134885)Nikolas Klauser
The need for `_LIBCPP_TEMPLATE_VIS` has been removed in #133233.
2025-04-04[libc++] Guard additional headers with _LIBCPP_HAS_LOCALIZATION (#131921)Louis Dionne
There were some remaining headers that were not guarded with _LIBCPP_HAS_LOCALIZATION, leading to errors when trying to use modules on platforms that don't support localization (since all the headers get pulled in when building the 'std' module). This patch brings these headers in line with what we do for every other header that depends on localization. This patch also requires including <picolibc.h> from <__configuration/platform.h> in order to define _NEWLIB_VERSION. In the long term, we should use a better approach for doing that, such as defining a macro in the __config_site header.
2025-02-27[NFC][libc++] Guard against operator& hijacking. (#128351)Mark de Wever
This set usage of operator& instead of std::addressof seems not be easy to "abuse". Some seem easy to misuse, like basic_ostream::operator<<, trying to do that results in compilation errors since the `widen` function is not specialized for the hijacking character type. Hence there are no tests.
2025-02-21[libc++] Qualify calls to nullary functions like __throw_foo (#122465)Louis Dionne
This is technically not necessary in most cases to prevent issues with ADL, but let's be consistent. This allows us to remove the libcpp-qualify-declval clang-tidy check, which is now enforced by the robust-against-adl clang-tidy check.
2025-01-29[libcxx] Use _ftelli64/_fseeki64 on Windows (#123128)Martin Storsjö
This allows using the full 64 bit range for file offsets. This should fix the issue reported downstream at https://github.com/mstorsjo/llvm-mingw/issues/462.
2024-12-21[libc++][C++03] Use `__cxx03/` headers in C++03 mode (#109002)Nikolas Klauser
This patch implements the forwarding to frozen C++03 headers as discussed in https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc. In the RFC, we initially proposed selecting the right headers from the Clang driver, however consensus seemed to steer towards handling this in the library itself. This patch implements that direction. At a high level, the changes basically amount to making each public header look like this: ``` // inside <vector> #ifdef _LIBCPP_CXX03_LANG # include <__cxx03/vector> #else // normal <vector> content #endif ``` In most cases, public headers are simple umbrella headers so there isn't much code in the #else branch. In other cases, the #else branch contains the actual implementation of the header.
2024-12-10[libc++] Add #if 0 block to all the top-level headers (#119234)Nikolas Klauser
Including The frozen C++03 headers results in a lot of formatting changes in the main headers, so this splits these changes into a separate commit instead. This is part of https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc.
2024-11-16[libc++] Avoid including <ostream> in <fstream> and <strstream> (#116014)Nikolas Klauser
This reduces the include time of `<fstream>` from ~800ms to ~500ms.
2024-11-06[libc++] Refactor the configuration macros to being always defined (#112094)Nikolas Klauser
This is a follow-up to #89178. This updates the `<__config_site>` macros.
2024-10-12[libc++][RFC] Always define internal feature test macros (#89178)Nikolas Klauser
Currently, the library-internal feature test macros are only defined if the feature is not available, and always have the prefix `_LIBCPP_HAS_NO_`. This patch changes that, so that they are always defined and have the prefix `_LIBCPP_HAS_` instead. This changes the canonical use of these macros to `#if _LIBCPP_HAS_FEATURE`, which means that using an undefined macro (e.g. due to a missing include) is diagnosed now. While this is rather unlikely currently, a similar change in `<__configuration/availability.h>` caught a few bugs. This also improves readability, since it removes the double-negation of `#ifndef _LIBCPP_HAS_NO_FEATURE`. The current patch only touches the macros defined in `<__config>`. If people are happy with this approach, I'll make a follow-up PR to also change the macros defined in `<__config_site>`.
2024-09-16[libc++][modules] Fix missing and incorrect includes (#108850)Louis Dionne
This patch adds a large number of missing includes in the libc++ headers and the test suite. Those were found as part of the effort to move towards a mostly monolithic top-level std module.
2024-09-16[libc++][modules] Guard carved-out headers more consistently (#108637)Louis Dionne
Several headers that should not be provided when localization or threads are disabled were not guarded. That works until one tries to build with modules and these headers get pulled in. Note that this could be cleaned up further into something more systematic, but this patch solves the immediate problems I ran into with the monolithic modulemap and doesn't create any new inconsistency that wasn't already there.
2024-08-06[libc++] Implements LWG3130. (#101889)Mark de Wever
This adds addressof at the required places in [input.output]. Some of the new tests failed since string used operator& internally. These have been fixed too. Note the new fstream tests perform output to a basic_string instead of a double. Using a double requires num_get specialization num_get<CharT, istreambuf_iterator<CharT, char_traits_operator_hijacker<CharT>> This facet is not present in the locale database so the conversion would fail due to a missing locale facet. Using basic_string avoids using the locale. As a drive-by fixes several bugs in the ofstream.cons tests. These tested ifstream instead of ofstream with an open mode. Implements: - LWG3130 [input.output] needs many addressof Closes #100246.
2024-06-18[libc++][NFC] Run clang-format on libcxx/include again (#95874)Louis Dionne
As time went by, a few files have become mis-formatted w.r.t. clang-format. This was made worse by the fact that formatting was not being enforced in extensionless headers. This commit simply brings all of libcxx/include in-line with clang-format again. We might have to do this from time to time as we update our clang-format version, but frankly this is really low effort now that we've formatted everything once.
2024-05-28[libc++] Make the __availability header a sub-header of __config (#93083)Louis Dionne
In essence, this header has always been related to configuration of the library but we didn't want to put it inside <__config> due to complexity reasons. Now that we have sub-headers in <__config>, we can move <__availability> to it and stop including it everywhere since we already obtain the required macros via <__config>.
2024-04-06[libc++] Implement LWG3430 disallow implicit conversion of the source ↵yronglin
arguments to `std::filesystem::path` when constructing `std::basic_*fstream` (#85079) Implement [LWG3430](https://wg21.link/LWG3430). --------- Signed-off-by: yronglin <yronglin777@gmail.com>
2024-03-14[libc++] Implements filebuf unbuffered. (#76629)Mark de Wever
When calling setbuf(nullptr, 0) before performing file operations it should set the file to unbuffered mode. Currently the code avoids buffering internally, but the underlying stream still can buffer. This is addressed by disabling the buffering of the underlying stream. Fixes: https://github.com/llvm/llvm-project/issues/60509
2024-03-03[libc++] Refactors fstream open. (#76617)Mark de Wever
This moves the duplicated code to one new function. This is a preparation to fix https://github.com/llvm/llvm-project/issues/60509
2024-02-29[libc++] Clean up includes of <__assert> (#80091)Louis Dionne
Originally, we used __libcpp_verbose_abort to handle assertion failures. That function was declared from all public headers. Since we don't use that mechanism anymore, we don't need to declare __libcpp_verbose_abort from all public headers, and we can clean up a lot of unnecessary includes. This patch also moves the definition of the various assertion categories to the <__assert> header, since we now rely on regular IWYU for these assertion macros. rdar://105510916
2024-01-07Reapply "[libc++][streams] P1759R6: Native handles and file streams" (#77190)Hristo Hristov
Fixes build on Windows in C++26 mode. Reverted in: https://github.com/llvm/llvm-project/commit/40c07b559aa6ab4bac074c943967d3207bc07ae0 Original PR: https://github.com/llvm/llvm-project/pull/76632 --------- Co-authored-by: Zingam <zingam@outlook.com>
2024-01-05Revert "[libc++][streams] P1759R6: Native handles and file streams (#76632)"Haowei Wu
This reverts commit 255f95a40377677dd762df5a1aa65bcbb4f75c79, which contains a breaking libcxx test on Windows when using C++26
2024-01-05[libc++][streams] P1759R6: Native handles and file streams (#76632)Hristo Hristov
Implements: `P1759R6` https://wg21.link/P1759R6 - https://eel.is/c++draft/filebuf - https://eel.is/c++draft/ifstream - https://eel.is/c++draft/ofstream - https://eel.is/c++draft/fstream --------- Co-authored-by: Zingam <zingam@outlook.com>
2023-12-19[libc++][print] Adds ostream overloads. (#73262)Mark de Wever
Finishes implementation of - P2093R14 Formatted output - P2539R4 Should the output of std::print to a terminal be synchronized with the underlying stream? Differential Revision: https://reviews.llvm.org/D156609
2023-12-18[libc++] Format the code base (#74334)Louis Dionne
This patch runs clang-format on all of libcxx/include and libcxx/src, in accordance with the RFC discussed at [1]. Follow-up patches will format the benchmarks, the test suite and remaining parts of the code. I'm splitting this one into its own patch so the diff is a bit easier to review. This patch was generated with: find libcxx/include libcxx/src -type f \ | grep -v 'module.modulemap.in' \ | grep -v 'CMakeLists.txt' \ | grep -v 'README.txt' \ | grep -v 'libcxx.imp' \ | grep -v '__config_site.in' \ | xargs clang-format -i A Git merge driver is available in libcxx/utils/clang-format-merge-driver.sh to help resolve merge and rebase issues across these formatting changes. [1]: https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
2023-12-05[libc++] Replace uses of _VSTD:: by std:: (#74331)Louis Dionne
As part of the upcoming clang-formatting of libc++, this patch performs the long desired removal of the _VSTD macro. See https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all for the clang-format proposal.
2023-12-04[libc++] Rename _LIBCPP_INLINE_VISIBILITY to _LIBCPP_HIDE_FROM_ABI (#74095)Louis Dionne
In preparation for running clang-format on the whole code base, we are also removing mentions of the legacy _LIBCPP_INLINE_VISIBILITY macro in favor of the newer _LIBCPP_HIDE_FROM_ABI. We're still leaving the definition of _LIBCPP_INLINE_VISIBILITY to avoid creating needless breakage in case some older patches are checked-in with mentions of the old macro. After we branch for LLVM 18, we can do another pass to clean up remaining uses of the macro that might have gotten introduced by mistake (if any) and remove the macro itself at the same time. This is just a minor convenience to smooth out the transition as much as possible. See https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all for the clang-format proposal.
2023-11-28[libc++] Properly guard std::filesystem with >= C++17 (#72701)Louis Dionne
<filesystem> is a C++17 addition. In C++11 and C++14 modes, we actually have all the code for <filesystem> but it is hidden behind a non-inline namespace __fs so it is not accessible. Instead of doing this unusual dance, just guard the code for filesystem behind a classic C++17 check like we normally do.
2023-11-24[libc++][NFC] Refactor _LIBCPP_AVAILABILITY_HAS_* macros to always be ↵philnik777
defined (#71002) This makes the conditionals quite a bit simpler to understand, since it avoids double negatives and makes sure we have <__availability> included. For vendors which use availability macros, it also enforces that they check when specific features are introduced and define the macro for their platform appropriately.
2023-11-17[libc++] Implement P2467R1: Support exclusive mode for fstreamsPragmaTwice
This patch brings std::ios_base::noreplace from P2467R1 to libc++. This requires compiling the shared library in C++23 mode since otherwise fstream::open(...) doesn't know about the new flag. Differential Revision: https://reviews.llvm.org/D137640 Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2023-11-07[libc++][hardening] Add `_LIBCPP_ASSERT_NON_NULL` to check for null pointers ↵Konstantin Varlamov
(#71428)
2023-10-27[libc++] Fix incorrect length check in std::basic_filebufLouis Dionne
This patch fixes an ASAN-found issue in std::basic_filebuf where we'd check the wrong size before proceeding to set our internal buffer to the externally-provided buffer, leading to the library trying to read from the incorrect buffer in underflow(). Thanks to Andrey Semin for the patch. Differential Revision: https://reviews.llvm.org/D154514
2023-10-06[libc++] Recategorize additional instantiations in the dylib as availability ↵Nikolas Klauser
macros Adding additional instantiations to the dylib isn't actually an ABI break as long as programs targeting an older dylib don't start to depend on them. Making additional instantiations a matter of availability allows us to add them without an ABI break. Reviewed By: #libc, ldionne, Mordante Spies: arichardson, ldionne, Mordante, libcxx-commits Differential Revision: https://reviews.llvm.org/D154796
2023-08-31[libc++] Move once_flag outside of <mutex>Louis Dionne
This allows including once_flag directly from <__locale> instead of depending on all of <mutex>, which requires threading. In turn, this makes it easier to support locales on platforms without threading. Drive-by change: clang-format once_flag.h and use _LIBCPP_HIDE_FROM_ABI Differential Revision: https://reviews.llvm.org/D155487
2023-06-28[libc++][hardening][NFC] Introduce `_LIBCPP_ASSERT_UNCATEGORIZED`.varconst
Replace most uses of `_LIBCPP_ASSERT` with `_LIBCPP_ASSERT_UNCATEGORIZED`. This is done as a prerequisite to introducing hardened mode to libc++. The idea is to make enabling assertions an opt-in with (somewhat) fine-grained controls over which categories of assertions are enabled. The vast majority of assertions are currently uncategorized; the new macro will allow turning on `_LIBCPP_ASSERT` (the underlying mechanism for all kinds of assertions) without enabling all the uncategorized assertions (in the future; this patch preserves the current behavior). Differential Revision: https://reviews.llvm.org/D153816
2023-06-27[libc++] Expand the contents of LIBCXX_ENABLE_FILESYSTEMLouis Dionne
Since LIBCXX_ENABLE_FILESYSTEM now truly represents whether the platform supports a filesystem (as opposed to whether the <filesystem> library is provided), we can provide a few additional classes from the <filesystem> library even when the platform does not have support for a filesystem. For example, this allows performing path manipulations using std::filesystem::path even on platforms where there is no actual filesystem. rdar://107061236 Differential Revision: https://reviews.llvm.org/D152382
2023-06-07[libc++] Rename availability macros for <filesystem>Louis Dionne
This makes it clearer that the availability macro only pertains to <filesystem>, and not to whether the platform has support for a file system. Differential Revision: https://reviews.llvm.org/D152172
2023-06-07[libc++] Roll up fstream support into filesystem supportLouis Dionne
LIBCXX_ENABLE_FILESYSTEM should represent whether the platform has support for a filesystem, not just whether we support <filesystem>. This patch slightly generalizes the setting to also encompass whether we provide <fstream>, since that only makes sense when a filesystem is supported. Differential Revision: https://reviews.llvm.org/D152168
2023-05-24Revert "[libc++] Apply _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION only in ↵Nikolas Klauser
classes that we have instantiated externally" This reverts commit b3c9150062dc4264afb4a3d2790f071c1ebe0743. There were unexpected breakages downstream. @EricWF is investigating.
2023-05-23[libc++] Apply _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION only in classes ↵Nikolas Klauser
that we have instantiated externally To make sure all member functions that require it are marked `_LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION` I compared the output of `objdump --syms lib/libc++.1.0.dylib` before and after, ignoring addresses. Reviewed By: #libc, ldionne Spies: Mordante, libcxx-commits, ldionne, arichardson, mstorsjo Differential Revision: https://reviews.llvm.org/D150896