gpt4 book ai didi

c++ - 使用 std::iterator 的 gRPC auth_context.h 使用最新的 VC++ 编译器产生不推荐使用的警告

转载 作者:行者123 更新时间:2023-12-04 14:16:19 31 4
gpt4 key购买 nike

使用最新的 Visual Studio 2019 16.5 预览版 2 编译器编译我使用 gRPC 的项目之一会产生此警告:

1>D:\...\grpcpp\impl\codegen\security\auth_context.h(38,19): warning C4996: 'std::iterator<std::input_iterator_tag,const grpc::AuthProperty,ptrdiff_t,const grpc::AuthProperty *,const grpc::AuthProperty &>': warning STL4015: The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. (The <iterator> header is NOT deprecated.) The C++ Standard has never required user-defined iterators to derive from std::iterator. To fix this warning, stop deriving from std::iterator and start providing publicly accessible typedefs named iterator_category, value_type, difference_type, pointer, and reference. Note that value_type is required to be non-const, even for constant iterators. You can define _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.

在提交错误报告之前,我想我已经在这里检查 gRPC 开发人员是否已经意识到这一点?

最佳答案

gRPC 不支持 C++17 的立场有点令人惊讶。我可能会错过它,但我在主 grpc 页面上没有看到任何不支持 C++11 以外的内容。我能找到的唯一支持矩阵是:https://grpc.io/docs/#official-support
通常,protobuf 和 gRPC 的使用都会在 Visual Studio 中导致大量警告,与此错误无关。对于生成的 cc 文件,取消警告 4267、4996 和 4244 是有帮助的。
对于此 C++17 警告/错误,由于问题出在标题中,因此您将在自己的非生成 cpp 文件上遇到问题。您不想在使用 header 的每个文件上禁用此类警告/错误,因为那样您将掩盖您自己的问题。我目前通过创建 grpcpp.suppress_errors.h 来解决问题:

#pragma once
#pragma warning ( push )
#pragma warning( disable : 4996)
#include <grpcpp/grpcpp.h>
#pragma warning ( pop )
然后,而不是包括 <grpcpp/grpcpp.h> , 包括 grpcc.suppress_errors.h .这有点愚蠢,但它会使您自己的代码免受抑制。

关于c++ - 使用 std::iterator 的 gRPC auth_context.h 使用最新的 VC++ 编译器产生不推荐使用的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59939678/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com