@Carl,
First, a disclaimer: Given the choice, I would not enable this rule on my code, which means I might not be the best person to discuss it, but I will share my reasoning when the rule was put in place:
Why is showing the pointer so important? Because the fact that the type is a pointer matters, you don’t work with pointers the same way as you work with other types. You must care about reference semantics, you must ensure that the pointed-to object outlives its use through the pointer, and maybe you must care about deleting the pointed-to object.
All these concerns remain valid, no matter if the pointer is hidden by a typedef or not.
When using a typedef to a pointer, the fact that there is a pointer is usually not really hidden: The name of the typedef usually helps to remember that the code is dealing with a pointer (I’ve seen many typedefs with a Ptr
suffix, for instance). I even suspect that codebases that require pointers to be explicit in auto
cases would not accept a typedef to a pointer unless the typedef name clearly states what is happening (it’s however not easy for us to write a rule about that because it would require dabbling with the semantic of a name).
When using auto
, there is no such possible help, therefore the pointer should remain visible for the declaration.
Therefore, I don’t think that, in general, ignoring a pointer contained within a typedef would be the right choice for this rule.
I’m however willing to consider the fact that this rule should not trigger if the “this is a pointer” information might be given by another name. For instance, in the following C++20 code:
for (std::forward_iterator auto it = cont.begin(); it != cont.end() ; ++it) {
The “this is a pointer” is no longer hidden, because it is explicit that it
is an iterator (for which the same kind of extra care must be taken as for pointers)
Do you think such a change would resolve your concern?