[C] Avoid aka types that just add tags

Programming / Compilers / GCC - rsandifo [138bc75d-0d04-0410-961f-82ee72b054a4] - 1 October 2019 08:56 EDT

diag-aka-1.c tests that:

struct T { int i; } T;
void *a; T *t = a;

produces:

request for implicit conversion from 'void *' to 'T *' {aka 'struct T *'} ...

But printing an aka for the tag seems a bit redundant when the tag name is the same as the typedef name. It's probably not going to be telling the user anything they don't already know, and can be distracting if "T" rather than "struct T" is the preferred choice for an exported interface. This is even more true if the tag is anonymous; e.g.:

struct { int i; } T;
void *a; T *t = a;

gives:

request for implicit conversion from 'void *' to 'T *' {aka 'struct *'}

Rather than just drop the test above, the patch instead tests for:

struct T { int i; } *T;

where seeing the tag definitely helps.

2019-10-01 Richard Sandiford

gcc/c/
- c-objc-common.c (useful_aka_type_p): New function. (print_type): Use it to decide whether an aka type is worth printing.

gcc/testsuite/
- gcc.dg/diag-aka-1.c (T): Turn into a pointer typedef. (foo): Update accordingly.
- gcc.dg/diag-aka-4.c: New test.

15d62210564 [C] Avoid aka types that just add tags
gcc/c/ChangeLog | 5 +++
gcc/c/c-objc-common.c | 69 ++++++++++++++++++++++++++++++++++++-
gcc/testsuite/ChangeLog | 6 ++++
gcc/testsuite/gcc.dg/diag-aka-1.c | 4 +--
gcc/testsuite/gcc.dg/diag-aka-4.c | 72 +++++++++++++++++++++++++++++++++++++++
5 files changed, 153 insertions(+), 3 deletions(-)

Upstream: gcc.gnu.org


  • Share