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

grpc::AuthPropertyIterator uses deprecated inheritance of std::iterator #25125

Closed
GBayliss opened this issue Jan 9, 2021 · 2 comments
Closed

Comments

@GBayliss
Copy link

GBayliss commented Jan 9, 2021

AuthPropertyIterator inherits from std::iterator. This has been deprecated in C++ 17 and causes MSVC to require a define to ignore and compile user code (which incidentally doesn't work, a separate problem for MS to resolve). This means that code intended to work with the grpc lib does not compile on MSVC with STD C++17 selected duet to deprecation warnings which cannot be ignored or otherwise #define'd away.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0174r1.html#2.1

Results from attempting to compile a user project in MSVC with STD C++17 selected:

..\grpc\include\grpcpp\impl\codegen\security\auth_context.h(38,19): error C4996: 'std::iterator<std::input_iterator_tag,const grpc::AuthProperty,ptrdiff_t,_Ty *,_Ty &>': 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.

Modifying the AuthPropertyIterator to use typedefs instead:

class AuthPropertyIterator{
 public:
  typedef std::input_iterator_tag iterator_category;
  typedef const AuthProperty value_type;
  typedef void difference_type;
  typedef void pointer;
  typedef void reference;
	  
  ~AuthPropertyIterator();
  AuthPropertyIterator& operator++();
  AuthPropertyIterator operator++(int);
  bool operator==(const AuthPropertyIterator& rhs) const;
  bool operator!=(const AuthPropertyIterator& rhs) const;
  const AuthProperty operator*();

 protected:
  AuthPropertyIterator();
  AuthPropertyIterator(const grpc_auth_property* property,
                       const grpc_auth_property_iterator* iter);

 private:
  friend class SecureAuthContext;
  const grpc_auth_property* property_;
  // The following items form a grpc_auth_property_iterator.
  const grpc_auth_context* ctx_;
  size_t index_;
  const char* name_;
};

Appears to fix the compilation error, but this may cause unintended side-effects. For safety, this should be reviewed by the security team to for testing.

@Spejik
Copy link

Spejik commented Oct 3, 2021

Sorry for commenting here, but any update on this? I've recently also encountered this problem, and the typedef fix seems to work pretty good, so if the security team could test it, to see if there are no issues? Thanks

@chrisse74
Copy link
Contributor

At least in protobuf a similar way was used to address this warning: protocolbuffers/protobuf#8741

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

No branches or pull requests

6 participants