Bug 99526 - Casts should retain typedef information
Summary: Casts should retain typedef information
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2021-03-10 18:57 UTC by David L.
Modified: 2021-08-22 04:47 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David L. 2021-03-10 18:57:21 UTC
Currently, any cast in C will produce the "resolved" type regardless of whether the cast is written using a typedef.  E.g.:

  typedef int i;
  typedef const int cint;
  typedef const i ci;
  char v;
  typeof((i)v)        => int;
  typeof((cint)v)     => int;
  typeof((ci)v)       => int;
  typeof((const i)v)  => int;

The IMHO ideal situation would be:

  typedef int i;
  typedef const int cint;
  typedef const i ci;
  char v;
  typeof((i)v)        => i;
  typeof((cint)v)     => int;
  typeof((ci)v)       => i;
  typeof((const i)v)  => i;

Note that since casts produce rvalues, qualifiers need to be stripped, and thus "ci" and "cint" shouldn't be used since the typedef itself contains a qualifier.

My rationale for this is twofold:

- systems (on POSIX: pid_t, uid_t, gid_t, ...) have some types that are of "unspecified" size, and it is helpful to be able to warn when these are intermixed.  Especially in printf() due to varargs calling:  there is no format specifier that is correct for these types.
- plugins may want to attach additional semantics to some typedefs, and this breaks if the plugin can't get at the typedef.