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

Fails to compile on Arch with gcc-14.2 #166

Closed
zhangyi1357 opened this issue Aug 6, 2024 · 5 comments · Fixed by #167
Closed

Fails to compile on Arch with gcc-14.2 #166

zhangyi1357 opened this issue Aug 6, 2024 · 5 comments · Fixed by #167

Comments

@zhangyi1357
Copy link
Contributor

What version of tRPC-Cpp are you using?

v1.2.0

What operating system and compiler are you using?

OS: Arch Linux on Windows 10 x86_64
Kernel: 5.15.133.1-microsoft-standard-WSL2
Compiler: g++ (GCC) 14.2.1 20240802

What did you do?

After cloning the project just run the following command under project root directory.

mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. && make -j8 && cd -
mkdir -p examples/helloworld/build && cd examples/helloworld/build &&cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. && make -j8 && cd -

What did you expect to see?

No compilation errors.

What did you see instead?

Just show the core errors:

  1. Non-compiling assignment operator
    related issue: GenericStringRef::operator= does not compile Tencent/rapidjson#718. it was fixed 8 years ago, but not a new release has been published and trpc-cpp uses 8 years old [email protected] (the newest release, lmao) without the fixed.
/home/zy/learning/trpc-cpp/cmake_third_party/rapidjson/include/rapidjson/document.h: In member function ‘rapidjson::GenericStringRef<CharType>& rapidjson::GenericStringRef<CharType>::operator=(const rapidjson::GenericStringRef<CharType>&)’:
/home/zy/learning/trpc-cpp/cmake_third_party/rapidjson/include/rapidjson/document.h:319:82: error: assignment of read-only member ‘rapidjson::GenericStringRef<CharType>::length’
  319 |     GenericStringRef& operator=(const GenericStringRef& rhs) { s = rhs.s; length = rhs.length; }
      |                                                                           ~~~~~~~^~~~~~~~~~~~
  1. Wrong use of std::negation_v
/home/zy/learning/trpc-cpp/trpc/config/trpc_conf_compatible.h:44:47: error: wrong number of template arguments (2, should be 1)
   44 |   if constexpr (std::negation_v<T, Json::Value> && std::negation_v<T, YAML::Node> &&
      |                                               ^
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/stl_pair.h:60,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/bits/stl_algobase.h:64:
/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/type_traits:271:27: note: provided for ‘template<class _Pp> constexpr const bool std::negation_v<_Pp>’
  271 |     inline constexpr bool negation_v = negation<_Pp>::value;
      |                           ^~~~~~~~~~
/home/zy/learning/trpc-cpp/trpc/config/trpc_conf_compatible.h:44:81: error: wrong number of template arguments (2, should be 1)
   44 |   if constexpr (std::negation_v<T, Json::Value> && std::negation_v<T, YAML::Node> &&
      |                                                                                 ^
/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/type_traits:271:27: note: provided for ‘template<class _Pp> constexpr const bool std::negation_v<_Pp>’
  271 |     inline constexpr bool negation_v = negation<_Pp>::value;

Full build log: build.log

How to fix

I'd like to fix above compilation problems.

For error 1, just do a patch on rapidjson like what has been done for spdlog.

For error 2, just do the following change:

diff --git a/trpc/config/trpc_conf_compatible.h b/trpc/config/trpc_conf_compatible.h
index e1eb5b2..e9125c1 100644
--- a/trpc/config/trpc_conf_compatible.h
+++ b/trpc/config/trpc_conf_compatible.h
@@ -41,8 +41,8 @@ std::optional<T> LoadConfig(const std::string& plugin_name, const std::string& c
                             const std::any& params = nullptr) {
   std::optional<T> ret;
   // Determine the type of support
-  if constexpr (std::negation_v<T, Json::Value> && std::negation_v<T, YAML::Node> &&
-                std::negation_v<T, std::map<std::string, std::string> >) {
+  if constexpr (std::negation_v<std::is_same<T, Json::Value>> && std::negation_v<std::is_same<T, YAML::Node>> &&
+                std::negation_v<std::is_same<T, std::map<std::string, std::string>>>) {
     TRPC_LOG_ERROR("Unknown type!");
     return ret;
   }
@zhangyi1357
Copy link
Contributor Author

When I tried to fix the issue, another problem with GoogleTest comes up.

In file included from /home/zy/learning/my-trpc-cpp/cmake_third_party/gtest/googletest/src/gtest-all.cc:42:
/home/zy/learning/my-trpc-cpp/cmake_third_party/gtest/googletest/src/gtest-death-test.cc: In function ‘bool testing::internal::StackGrowsDown()’:
/home/zy/learning/my-trpc-cpp/cmake_third_party/gtest/googletest/src/gtest-death-test.cc:1301:24: error: ‘dummy’ may be used uninitialized [-Werror=maybe-uninitialized]
 1301 |   StackLowerThanAddress(&dummy, &result);
      |   ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

It has been solved by google/googletest#3024, we only need to update GoogleTest to use version 1.11.0 or newer.

@weimch
Copy link
Contributor

weimch commented Aug 14, 2024

When using cc_proto_library, bazel will use a specific version of protobuf to generate *.pb.h/.*pb.cc stub code.

Starting from bazel-7, we can't change version of protobuf by simply declare a com_google_protobuf bazel repository (it does work in bazel-1~bazel-6). So the stub code will be genreated using protobuf-3.21.8 and can't compatible with trpc-cpp protobuf-3.15.8 which causes compile error.

To resolve this problem, just downgrade bazel version to bazel-6.

@weimch weimch closed this as completed Aug 14, 2024
@zhangyi1357
Copy link
Contributor Author

@weimch I'm not using Bazel, I'm using CMake.

@weimch weimch reopened this Aug 15, 2024
@weimch
Copy link
Contributor

weimch commented Aug 15, 2024

@weimch I'm not using Bazel, I'm using CMake.

sor, thought you were the guy asking compile error in private.

@weimch
Copy link
Contributor

weimch commented Nov 15, 2024

Already solved by @zhangyi1357 at #167. Thanks for contribution.

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

Successfully merging a pull request may close this issue.

2 participants