5

I have a custom forward iterator type. It declares (among other stuff) this:

Iter& operator++();
Iter operator++(int);

clang-tidy complains about cert-dcl21-cpp (Clang-Tidy: Overloaded 'operator++' returns a non-constant object instead of a constant object type)

Now, naïve as I am, I changed the declaration to

Iter& operator++();
Iter const operator++(int);

Well, it now complains about readability-const-return-type (Return type 'const IndexAtomListPtr::Iter' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness)

How can I satisfy clang-tidy?

The answer to the related question: overloaded "operator++" returns a non const, and clang-tidy complains is not sufficient, as it is exactly what I tried, but got the readability-const-return-type complain

  • 1
    Does this answer your question? [overloaded "operator++" returns a non const, and clang-tidy complains](https://stackoverflow.com/questions/52871026/overloaded-operator-returns-a-non-const-and-clang-tidy-complains) – pablo285 Jun 03 '21 at 09:55
  • I found this question before, but it does not provide an answer, except saying "do what clang-tidy says", which I did, but it keeps complaining. – Mischael Schill Jun 04 '21 at 10:28
  • Does it complain if you return an actual [const_iterator](https://stackoverflow.com/questions/309581/what-is-the-difference-between-const-iterator-and-non-const-iterator-in-the-c)? – Bob__ Jun 04 '21 at 11:22
  • Have you tried option 2, i.e. l-value ref qualifying the overload? If that doesn't work either then ping me in a comment. The question is still a duplicate, so that means another answer should be added on the target. – cigien Aug 03 '21 at 23:53

0 Answers0