Thanks a lot for pointing out the error. v3 has reverted the changes to be the same as v1 and rebased.
The explanation of this patch doesn't seem right. The commit message says "... eliminate cast-away-const ...", but that is not what is happening in the code. For example, in
p1 is of type pointer-to-const-void, which is then cast into pointer-to-const-pointer-to-DumpableObject (which preserves the qualifier, because it's pointer-to-const-xxx on both sides), which is then dereferenced to result in type const-pointer-to-DumpableObject (type DumpableObject * const, not const DumpableObject *), which is then assigned by value to obj1 of type pointer-to-DumpableObject. This is all entirely correct.
Now there is nothing wrong with making the receiving obj1 have an additional const qualification, if that's the promise you want to make about it for that scope. But that's separate from preserving the qualifier on p1. And it's incorrect to claim that this is fixing an existing cast-away-const issue.
Thanks for the explanation, you’re right.
The original p1/p2 are pointers to pointers, and the const qualifier only applies to the outer pointer. After dereferencing, the second-level pointer (DumpableObject *) is obtained, and my change simply adds const qualification to that pointer.
So this is not fixing a cast-away-const issue, but rather tightening the const qualification of the local variables.
Independent of that, there appears to be some not quite finished code here: