From ee757a2210508bbf7efccca421af184ed320c10e Mon Sep 17 00:00:00 2001 From: Eric Dorland Date: Tue, 17 Feb 2026 16:08:38 -0500 Subject: [PATCH] Fix compile failure on MacOS X std::shared_ptr::unique() is deprecated in C++17 and removed in C++20. Inspired by PR#1362. Snippet of the failure: ``` In file included from ../../src/terminal/terminal.h:42: ../../src/terminal/terminalframebuffer.h:431:23: error: 'unique' is deprecated [-Werror,-Wdeprecated-declarations] 431 | if ( !mutable_row.unique() ) { | ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/shared_ptr.h:752:3: note: 'unique' has been explicitly marked deprecated here 752 | _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI bool unique() const _NOEXCEPT { return use_count() == 1; } | ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:731:41: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX17' 731 | # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED | ^ /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:696:49: note: expanded from macro '_LIBCPP_DEPRECATED' 696 | # define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) | ^ 1 error generated. ``` --- src/terminal/terminalframebuffer.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/terminal/terminalframebuffer.h b/src/terminal/terminalframebuffer.h index 9039d4e..131ee18 100644 --- a/src/terminal/terminalframebuffer.h +++ b/src/terminal/terminalframebuffer.h @@ -427,8 +427,9 @@ public: if ( row == -1 ) row = ds.get_cursor_row(); row_pointer& mutable_row = rows.at( row ); - // If the row is shared, copy it. - if ( !mutable_row.unique() ) { + // If the row is shared, copy it. This is only safe because mosh isn't + // multi-threaded. + if ( mutable_row.use_count() > 1 ) { mutable_row = std::make_shared( *mutable_row ); } return mutable_row.get();