[Bug c++/87850] Add fix-it hint for "invalid conversion from 'X' to 'X*'"

2024-11-27 Thread dmalcolm at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87850

David Malcolm  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #6 from David Malcolm  ---
Should be implemented by the above patch for GCC 15.

[Bug c++/87850] Add fix-it hint for "invalid conversion from 'X' to 'X*'"

2024-11-27 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87850

--- Comment #5 from GCC Commits  ---
The master branch has been updated by David Malcolm :

https://gcc.gnu.org/g:5336b63fe81029cfd790208fbc69a08c70b82b01

commit r15-5738-g5336b63fe81029cfd790208fbc69a08c70b82b01
Author: David Malcolm 
Date:   Wed Nov 27 19:21:15 2024 -0500

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 

[Bug c++/87850] Add fix-it hint for "invalid conversion from 'X' to 'X*'"

2024-11-22 Thread dmalcolm at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87850

David Malcolm  changed:

   What|Removed |Added

URL|https://gcc.gnu.org/ml/gcc- |https://gcc.gnu.org/piperma
   |patches/2018-11/msg00802.ht |il/gcc-patches/2024-Novembe
   |ml  |r/669830.html

--- Comment #4 from David Malcolm  ---
6 years later, a v5 patch:
https://gcc.gnu.org/pipermail/gcc-patches/2024-November/669830.html

[Bug c++/87850] Add fix-it hint for "invalid conversion from 'X' to 'X*'"

2024-11-21 Thread dmalcolm at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87850

--- Comment #3 from David Malcolm  ---
v4 patch: https://gcc.gnu.org/legacy-ml/gcc-patches/2018-11/msg02617.html

[Bug c++/87850] Add fix-it hint for "invalid conversion from 'X' to 'X*'"

2024-11-21 Thread dmalcolm at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87850

--- Comment #2 from David Malcolm  ---
v2 patch: https://gcc.gnu.org/legacy-ml/gcc-patches/2018-11/msg01408.html
v3 patch: https://gcc.gnu.org/legacy-ml/gcc-patches/2018-11/msg01658.html

[Bug c++/87850] Add fix-it hint for "invalid conversion from 'X' to 'X*'"

2018-11-09 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87850

David Malcolm  changed:

   What|Removed |Added

   Keywords||patch
 Status|UNCONFIRMED |ASSIGNED
URL||https://gcc.gnu.org/ml/gcc-
   ||patches/2018-11/msg00802.ht
   ||ml
   Last reconfirmed||2018-11-09
   Assignee|unassigned at gcc dot gnu.org  |dmalcolm at gcc dot 
gnu.org
 Ever confirmed|0   |1

--- Comment #1 from David Malcolm  ---
Candidate patch: https://gcc.gnu.org/ml/gcc-patches/2018-11/msg00802.html