File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 44// This file exists to simplify adding C++ source location to python StatusNotOk
55// traces. See: b/266066084 for details.
66
7+ #include < type_traits>
8+
79#include " absl/status/status.h"
810#include " util/task/status_builder.h"
911
@@ -23,24 +25,26 @@ util::StatusBuilder DisplaySourceLocationInPython(util::StatusBuilder sb);
2325util::StatusBuilder DoNotDisplaySourceLocationInPython (util::StatusBuilder sb);
2426
2527// Annotate the StatusOr<T> to display the c++ SourceLocation in python.
28+ // The argument is a reference type and the return value is a value type.
29+ // This avoids returning a reference to a stack variable.
2630template <typename StatusOrT>
27- StatusOrT DisplaySourceLocationInPython (StatusOrT&& s_or_t ) {
31+ std:: decay_t < StatusOrT> DisplaySourceLocationInPython (StatusOrT&& s_or_t ) {
2832 if (s_or_t .ok ()) {
2933 return s_or_t ;
3034 }
3135 absl::Status status_with_payload = DisplaySourceLocationInPython (
3236 s_or_t .status ());
33- return StatusOrT{status_with_payload};
37+ return std:: decay_t < StatusOrT> {status_with_payload};
3438}
3539
3640template <typename StatusOrT>
37- StatusOrT DoNotDisplaySourceLocationInPython (StatusOrT&& s_or_t ) {
41+ std:: decay_t < StatusOrT> DoNotDisplaySourceLocationInPython (StatusOrT&& s_or_t ) {
3842 if (s_or_t .ok ()) {
3943 return s_or_t ;
4044 }
4145 absl::Status status_with_payload = DoNotDisplaySourceLocationInPython (
4246 s_or_t .status ());
43- return StatusOrT{status_with_payload};
47+ return std:: decay_t < StatusOrT> {status_with_payload};
4448}
4549
4650} // namespace google
You can’t perform that action at this time.
0 commit comments