Skip to content

Commit 8f4deff

Browse files
authored
[libcxx][fstream][NFC] Make __failed helper lambda a member function (#149390)
This patch makes the `__failed` lambda a member function on `fstream`. This fixes two LLDB expression evaluation test failures that got introduced with #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.
1 parent 100d8f7 commit 8f4deff

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

libcxx/include/fstream

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ private:
401401
}
402402
}
403403
}
404+
405+
_LIBCPP_HIDE_FROM_ABI typename traits_type::int_type __overflow_failed() {
406+
if (this->pptr() == this->epptr() + 1) {
407+
this->pbump(-1); // lose the character we overflowed above -- we don't really have a
408+
// choice since we couldn't commit the contents of the put area
409+
}
410+
return traits_type::eof();
411+
}
404412
};
405413

406414
template <class _CharT, class _Traits>
@@ -821,14 +829,6 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
821829

822830
template <class _CharT, class _Traits>
823831
typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::overflow(int_type __c) {
824-
auto __failed = [this]() {
825-
if (this->pptr() == this->epptr() + 1) {
826-
this->pbump(-1); // lose the character we overflowed above -- we don't really have a
827-
// choice since we couldn't commit the contents of the put area
828-
}
829-
return traits_type::eof();
830-
};
831-
832832
if (__file_ == nullptr)
833833
return traits_type::eof();
834834
__write_mode();
@@ -850,7 +850,7 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
850850
if (__always_noconv_) {
851851
size_t __n = static_cast<size_t>(this->pptr() - this->pbase());
852852
if (std::fwrite(this->pbase(), sizeof(char_type), __n, __file_) != __n) {
853-
return __failed();
853+
return __overflow_failed();
854854
}
855855
} else {
856856
if (!__cv_)
@@ -864,22 +864,22 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
864864
do {
865865
codecvt_base::result __r = __cv_->out(__st_, __b, __p, __end, __extbuf_, __extbuf_ + __ebs_, __extbuf_end);
866866
if (__end == __b) {
867-
return __failed();
867+
return __overflow_failed();
868868
}
869869

870870
// No conversion needed: output characters directly to the file, done.
871871
if (__r == codecvt_base::noconv) {
872872
size_t __n = static_cast<size_t>(__p - __b);
873873
if (std::fwrite(__b, 1, __n, __file_) != __n) {
874-
return __failed();
874+
return __overflow_failed();
875875
}
876876
break;
877877

878878
// Conversion successful: output the converted characters to the file, done.
879879
} else if (__r == codecvt_base::ok) {
880880
size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_);
881881
if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) {
882-
return __failed();
882+
return __overflow_failed();
883883
}
884884
break;
885885

@@ -888,13 +888,13 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
888888
} else if (__r == codecvt_base::partial) {
889889
size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_);
890890
if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) {
891-
return __failed();
891+
return __overflow_failed();
892892
}
893893
__b = const_cast<char_type*>(__end);
894894
continue;
895895

896896
} else {
897-
return __failed();
897+
return __overflow_failed();
898898
}
899899
} while (true);
900900
}

0 commit comments

Comments
 (0)