Skip to content

Commit a0226c3

Browse files
Michael137MarkMurrayARM
authored andcommitted
Automerge: [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 llvm/llvm-project#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. (cherry picked from commit 8f4deff)
2 parents c6dae09 + 362b99f commit a0226c3

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
@@ -402,6 +402,14 @@ private:
402402
}
403403
}
404404
}
405+
406+
_LIBCPP_HIDE_FROM_ABI typename traits_type::int_type __overflow_failed() {
407+
if (this->pptr() == this->epptr() + 1) {
408+
this->pbump(-1); // lose the character we overflowed above -- we don't really have a
409+
// choice since we couldn't commit the contents of the put area
410+
}
411+
return traits_type::eof();
412+
}
405413
};
406414

407415
template <class _CharT, class _Traits>
@@ -822,14 +830,6 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
822830

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

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

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

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

897897
} else {
898-
return __failed();
898+
return __overflow_failed();
899899
}
900900
} while (true);
901901
}

0 commit comments

Comments
 (0)