aboutsummaryrefslogtreecommitdiff
path: root/gcc/expr.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2024-11-27 19:21:15 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2024-11-27 19:21:15 -0500
commit5336b63fe81029cfd790208fbc69a08c70b82b01 (patch)
treeef4e3d88378a00915f2a6e2a508781450aacbfe2 /gcc/expr.cc
parent9f06b910a840d8ed06e27942bc23f260a0e0ccf3 (diff)
downloadgcc-5336b63fe81029cfd790208fbc69a08c70b82b01.zip
gcc-5336b63fe81029cfd790208fbc69a08c70b82b01.tar.gz
gcc-5336b63fe81029cfd790208fbc69a08c70b82b01.tar.bz2
C/C++: add fix-it hints for missing '&' and '*' (v5) [PR87850]
This patch adds a note with a fix-it hint to various pointer-vs-non-pointer diagnostics, suggesting the addition of a leading '&' or '*'. For example, note the ampersand fix-it hint in the following: demo.c: In function 'int main()': demo.c:5:22: error: invalid conversion from 'pthread_key_t' {aka 'unsigned int'} to 'pthread_key_t*' {aka 'unsigned int*'} [-fpermissive] 5 | pthread_key_create(key, NULL); | ^~~ | | | pthread_key_t {aka unsigned int} demo.c:5:22: note: possible fix: take the address with '&' 5 | pthread_key_create(key, NULL); | ^~~ | & In file included from demo.c:1: /usr/include/pthread.h:1122:47: note: initializing argument 1 of 'int pthread_key_create(pthread_key_t*, void (*)(void*))' 1122 | extern int pthread_key_create (pthread_key_t *__key, | ~~~~~~~~~~~~~~~^~~~~ gcc/c-family/ChangeLog: PR c++/87850 * c-common.cc: Include "gcc-rich-location.h". (maybe_emit_indirection_note): New function. * c-common.h (maybe_emit_indirection_note): New decl. (compatible_types_for_indirection_note_p): New decl. gcc/c/ChangeLog: PR c++/87850 * c-typeck.cc (compatible_types_for_indirection_note_p): New function. (convert_for_assignment): Call maybe_emit_indirection_note for pointer vs non-pointer diagnostics. gcc/cp/ChangeLog: PR c++/87850 * call.cc (convert_like_real): Call maybe_emit_indirection_note for "invalid conversion" diagnostic. * typeck.cc (compatible_types_for_indirection_note_p): New function. gcc/testsuite/ChangeLog: PR c++/87850 * c-c++-common/indirection-fixits.c: New test. * g++.dg/template/error60.C: Add fix-it hint to expected output. * g++.dg/template/error60a.C: Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/expr.cc')
0 files changed, 0 insertions, 0 deletions