Finding original declaration which is suffering from discarding a qualifier is somewhat tricky and it doesn't always make sense in all of the contexts that DiagnoseAssignmentResult is called.
I haven't figured out yet how to make this change work for ObjC Setters which I think is the only place left which should handle this diagnostic.
Current approach is sort of best-effort, but doesn't really guarantee much.
Alternative way to go would be to factor this extra diagnostic out and write it in a similar fashion to DiagnoseSelfAssignment and call it in some of the contexts when note could be useful.
The problem I see with that, is that it would have issues with handling overriden assignment operators or would not work for non built-in types.
Test Plan:
$ cat test.c int main() { char * c; char const ** c2 = &c; char * d; char volatile ** d2 = &d; }
test.c:3:17: warning: initializing 'const char **' with an expression of type 'char **' discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers] char const ** c2 = &c; ^ ~~ test.c:3:3: note: nested pointer type with discarded 'const' qualifier char const ** c2 = &c; ^~~~~~~~~~~~~~~~ test.c:6:20: warning: initializing 'volatile char **' with an expression of type 'char **' discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers] char volatile ** d2 = &d; ^ ~~ test.c:6:3: note: nested pointer type with discarded 'const' qualifier char volatile ** d2 = &d; ^~~~~~~~~~~~~~~~~~~
This is the place which I suspect may trigger this warning, but I need to read the code more careful to come up with an example.