Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++20 no member named 'derived_from' in namespace 'std' #19364

Open
Tradias opened this issue Nov 22, 2024 · 3 comments · Fixed by #19391
Open

C++20 no member named 'derived_from' in namespace 'std' #19364

Tradias opened this issue Nov 22, 2024 · 3 comments · Fixed by #19391

Comments

@Tradias
Copy link
Contributor

Tradias commented Nov 22, 2024

What version of protobuf and what language are you using?
Version: v28.3
Language: C++

What operating system (Linux, Windows, ...) and version?

Ubuntu 20.04.6, Github runner (see https://github.com/actions/runner-images/blob/ubuntu20/20241117.1/images/ubuntu/Ubuntu2004-Readme.md)

What runtime / compiler are you using (e.g., python version or gcc version)

Clang 10 with -stdlib=libc++

What did you do?

Compile any program that includes src/google/protobuf/port.h.

Additionally, regardless of the compiler, the static_assertion inside google::protobuf::internal::AssertDownCast from src/google/protobuf/port.h will always fail.

What did you expect to see

Compiles cleanly

What did you see instead?

In file included from /home/runner/work/asio-grpc/vcpkg_installed/x64-linux-clang-release/include/google/protobuf/io/coded_stream.h:114:
Error: /home/runner/work/asio-grpc/vcpkg_installed/x64-linux-clang-release/include/google/protobuf/port.h:177:10: error: no member named 'derived_from' in namespace 'std'
    std::derived_from<std::remove_pointer_t<To>,
    ~~~~~^
Error: /home/runner/work/asio-grpc/vcpkg_installed/x64-linux-clang-release/include/google/protobuf/port.h:177:48: error: expected '(' for function-style cast or type construction
    std::derived_from<std::remove_pointer_t<To>,
                      ~~~~~~~~~~~~~~~~~~~~~~~~~^

Anything else we should know about your project / environment

Suggested fixes:

Either keep using C++20

Add the following to the top of src/google/protobuf/port.h

#if __cpp_lib_concepts >= 202002L
#include <concepts>
#endif

Clean up this usage of concepts

static_assert(!requires {

Change

#if defined(__cpp_concepts)
  static_assert(!requires {
    std::derived_from<std::remove_pointer_t<To>,
                      typename std::remove_pointer_t<To>::MessageLite>;
  });

to

#if __cpp_lib_concepts >= 202002L
  static_assert(!std::derived_from<std::remove_pointer_t<To>,
                      typename std::remove_pointer_t<To>::MessageLite>);
#endif

Or switch to older C++ standard

Replace std::derived_from with

template<class Derived, class Base>
struct DerivedFrom : std::integral_constant<bool, (std::is_base_of<Base, Derived>::value &&
    std::is_convertible<const volatile Derived*, const volatile Base*>::value)>
{};
@Tradias Tradias added the untriaged auto added to all issues by default when created. label Nov 22, 2024
@acozzette
Copy link
Member

Thank you for the bug report. We would be happy to review a pull request if you would like to send us one, but if not then we will probably get around to this eventually.

@acozzette acozzette added c++ bug and removed untriaged auto added to all issues by default when created. labels Nov 22, 2024
copybara-service bot pushed a commit that referenced this issue Nov 25, 2024
Fixes #19364

Closes #19372

COPYBARA_INTEGRATE_REVIEW=#19372 from Tradias:remove-downcast f126025
FUTURE_COPYBARA_INTEGRATE_REVIEW=#19372 from Tradias:remove-downcast f126025
PiperOrigin-RevId: 700053807
@acozzette
Copy link
Member

Unfortunately we do still use this DownCast() function in some internal-only code, so I wasn't able to submit your entire change.

@acozzette acozzette reopened this Nov 26, 2024
@Tradias
Copy link
Contributor Author

Tradias commented Nov 30, 2024

@acozzette that is surprising. I thought you guys are using C++20 internally. In that case just remove the static_assert seeing that OSS doesn't need it (function is never used) and you don't have C++20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants