C++: 使用 abseil >= 20260107.0 时,公共 grpcpp 头文件会生成 -Wdeprecated-declarations 警告(absl::MutexLock 指针构造函数、IdentityKeyCertPair)
作者: bilalba创建于 2026年9月17日更新于 2026年9月29日
标签kind/buglang/c++priority/P2untriaged
What did you do? Compile a translation unit that does nothing but include the public umbrella header, against an abseil release from 20260107.0 or later. repro.cc:cpp#include "grpcpp/grpcpp.h" `BUILD.bazel`:Pythonload("@rules_cc//cc:defs.bzl", "cc_library")cc_library(name = "repro", srcs = ["repro.cc"], deps = ["@grpc//:grpc++"]) MODULE.bazel:```Pythonbazel_dep(name = "grpc", version = "1.83.0")bazel_dep(name = "abseil-cpp", version = "20260526.0")Then bazel build //:repro. The root module's abseil wins under MVS over the 20250512.1 that gRPC's own MODULE.bazel names, which is the normal situation for any consumer that also depends on a current abseil. ### What did you expect to see? A clean compile. The headers under include/grpcpp/ are public, so warnings raised inside them land on every downstream translation unit, and downstream cannot fix them. ### What did you see instead? 29 warnings from that single include, all -Wdeprecated-declarations, all inside include/grpcpp/: external/grpc+/include/grpcpp/completion_queue.h:390:31: warning: 'MutexLock' is deprecated: Use the constructor that takes a reference instead [-Wdeprecated-declarations] 390 | grpc::internal::MutexLock l(&server_list_mutex_) 633 | [[deprecated("Use the constructor that takes a reference instead")]] 339 357 387 416 451 499 554 567 580 604 642 659 674 693 716 760 775 797 830 846 868 889 Sites on v1.83.0 (line numbers): | header | count | lines | grpcpp/support/server_callback.h | 22 | 339 357 387 416 451 499 554 567 580 604 642 659 674 693 716 760 775 797 830 846 868 889 | grpcpp/server_context.h | 3 | 427 505 521 | grpcpp/completion_queue.h | 3 | 390 397 403 | grpcpp/security/tls_certificate_provider.h | 1 | 179 | 28 are grpc::internal::MutexLock l(&mu) taking the address of a member mutex. grpc::internal::MutexLock is absl::MutexLock via using MutexLock = absl::MutexLock; in src/core/util/sync.h:47, and abseil marked the pointer-taking constructors [[deprecated]] in abseil commit 6d8e1a5c ("Mark legacy Mutex methods and MutexLock pointer constructors as deprecated", 2026-01-06, first shipped in 20260107.0). The reference-taking constructor has existed since 20250814.0. The remaining one is gRPC's own deprecation of its own type: tls_certificate_provider.h:179 declares
内容来源: grpc/grpc