protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Fix warnings when compiling protobuf with C++20

Open hungptit opened this issue 1 year ago • 2 comments

What is the problem?

I got these warnings when compiling gRPC libraries on Linux.

/home/hungptit/working/experiments/_deps/grpc-src/third_party/protobuf/src/google/protobuf/map.cc:124:36: warning: implicit capture of 'this' with a capture default of '=' is deprecated [-Wdeprecated-this-capture]
  124 |       const TableEntryPtr* table = table_;
      |                                    ^
/home/hungptit/working/experiments/_deps/grpc-src/third_party/protobuf/src/google/protobuf/map.cc:123:24: note: add an explicit capture of 'this' to capture '*this' by reference
  123 |     const auto loop = [=](auto destroy_node) {
      |                        ^
      |                         , this
1 warning generated.
/home/hungptit/working/experiments/_deps/grpc-src/third_party/protobuf/src/google/protobuf/map.cc:124:36: warning: implicit capture of 'this' with a capture default of '=' is deprecated [-Wdeprecated-this-capture]
  124 |       const TableEntryPtr* table = table_;
      |                                    ^
/home/hungptit/working/experiments/_deps/grpc-src/third_party/protobuf/src/google/protobuf/map.cc:123:24: note: add an explicit capture of 'this' to capture '*this' by reference
  123 |     const auto loop = [=](auto destroy_node) {
      |                        ^
      |                         , this
1 warning generated.

We can reproduce these warnings by configuring protobuf using these steps:

cmake ./ -DCMAKE_CXX_COMPILER=clang++ -Dprotobuf_BUILD_TESTS=OFF -DABSL_PROPAGATE_CXX_STD=ON -CMAKE_CXX_STANDARD=20 -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build ./

Solution

  • Capture this and input by values.

hungptit avatar Aug 10 '24 21:08 hungptit

@mkruskal-google Could you take a look at this simple PR?

hungptit avatar Aug 24 '24 00:08 hungptit

@hungptit - Can you see if the changes that recently landed to resolve #17882 fix this issue for you?

JasonLunn avatar Oct 11 '24 15:10 JasonLunn

Going to close this. Please reopen if https://github.com/protocolbuffers/protobuf/commit/f8bf5eddb4e579c51ff2d98a11fc7dba91aa2950 did not resolve your issue.

tonyliaoss avatar Nov 21 '24 21:11 tonyliaoss