typeof is supported by many C compilers essentially forever, but not part of the standard. It is finally accepted to C23 thanks to JeanHeyd Meneide.
There were minor incompatibilities and problems that had to be resolved first. The main question was whether it should drop qualifiers or not. Dropping qualifiers seems more useful, because one can always add them back.
const int i = 0;
const typeof_unqual(i) j = 1;
One example, where one needs the qualifiers is when redeclaring variables:
extern const int i;
extern typeof(i) i;
Existing implementation preserve qualifiers. GCC did drop _Atomic (as of 2020) so I changed this for consistency. But this was required for stdatomic.h so a way to drop qualifiers was needed first. It should be possible to drop qualifiers by forcing a lvalue conversion, e.g.:
const int i = 0;
typeof(0,i) j;
j = 1;
This also did not work and needed a fix. One way is to use a cast to the type as casts remove qualifiers, but this requires to use typeof twice.
Assignment should also drop qualifiers.
Refs. n1229, n2593, n2619, n2685, n2724, n2899, n2926
(Regressions which needed to be fixed: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98029, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97981, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98260)