tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

[C++20] Failed to build with error C2039: 'unique': is not a member of 'std::shared_ptr<td::SqliteConnectionSafe>' #2568

Closed Od0VxibTqto6Hs closed 11 months ago

Od0VxibTqto6Hs commented 1 year ago

Summary

Tdlib failed to build with error C2039: 'unique': is not a member of 'std::shared_ptr<td::SqliteConnectionSafe>' on /std:c++20 option.

This function was deprecated in C++17 and removed in C++20 because use_count is only an approximation in multithreaded environment.

https://en.cppreference.com/w/cpp/memory/shared_ptr/unique https://learn.microsoft.com/en-us/cpp/standard-library/shared-ptr-class?view=msvc-170#unique

Additional Option

set _CL_=/std:c++20

Error Info

TdDb.cpp
td\telegram\TdDb.cpp(277,11): error C2039: 'unique': is not a member of 'std::shared_ptr<td::SqliteConnectionSafe>'
td/telegram/TdDb.h(119,8): message : see declaration of 'std::shared_ptr<td::SqliteConnectionSafe>'
td\telegram\TdDb.cpp(320,3): error C2039: 'unique': is not a member of 'std::shared_ptr<td::BinlogKeyValue<td::ConcurrentBinlog>>'
td/telegram/TdDb.h(180,8): message : see declaration of 'std::shared_ptr<td::BinlogKeyValue<td::ConcurrentBinlog>>'
td\telegram\TdDb.cpp(322,3): error C2039: 'unique': is not a member of 'std::shared_ptr<td::BinlogKeyValue<td::ConcurrentBinlog>>'
td/telegram/TdDb.h(180,8): message : see declaration of 'std::shared_ptr<td::BinlogKeyValue<td::ConcurrentBinlog>>'

Related Code

https://github.com/tdlib/td/blob/a7f8ff6eefbb4951d62b9e29bc4f7b95a28a46f0/td/telegram/TdDb.cpp#L277 https://github.com/tdlib/td/blob/a7f8ff6eefbb4951d62b9e29bc4f7b95a28a46f0/td/telegram/TdDb.cpp#L320 https://github.com/tdlib/td/blob/a7f8ff6eefbb4951d62b9e29bc4f7b95a28a46f0/td/telegram/TdDb.cpp#L322

levlam commented 1 year ago

TDLib has multiple incompatibilities with C++20 and currently is supposed to be built with a C++14 compiler as specified in CMakeLists.txt.

This function was deprecated in C++17 and removed in C++20 because use_count is only an approximation in multithreaded environment.

And our use case was perfectly legitimate, because we just check that only the current thread owns the shared pointer before completely destroying it. It was a sanity check, which is now harder to implement in C++20.

Od0VxibTqto6Hs commented 1 year ago

TDLib has multiple incompatibilities with C++20 and currently is supposed to be built with a C++14 compiler as specified in CMakeLists.txt. ...

Thanks for your reply and provide the information.