c, c++: Accept __builtin_classify_type (typename)
commit53d834a7fae3afffebb45a2d66908f705773a7fc
authorJakub Jelinek <jakub@redhat.com>
Wed, 20 Sep 2023 16:37:29 +0000 (20 18:37 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 20 Sep 2023 16:37:29 +0000 (20 18:37 +0200)
tree4af979256b3f85649ada1d5cabc08c21cf6947db
parent27282dc0931484c31fa391772499d878afcc746a
c, c++: Accept __builtin_classify_type (typename)

As mentioned in my stdckdint.h mail, __builtin_classify_type has
a problem that argument promotion (the argument is passed to ...
prototyped builtin function) means that certain type classes will
simply never appear.
I think it is too late to change how it behaves, lots of code in the
wild might rely on the current behavior.

So, the following patch adds option to use a typename rather than
expression as the operand to the builtin, making it behave similarly
to sizeof, typeof or say the clang _Generic extension where the
first argument can be there not just expression, but also typename.

I think we have other prior art here, e.g. __builtin_va_arg also
expects typename.

I've added this to both C and C++, because it would be weird if it
supported it only in C and not in C++.

2023-09-20  Jakub Jelinek  <jakub@redhat.com>

gcc/
* builtins.h (type_to_class): Declare.
* builtins.cc (type_to_class): No longer static.  Return
int rather than enum.
* doc/extend.texi (__builtin_classify_type): Document.
gcc/c/
* c-parser.cc (c_parser_postfix_expression_after_primary): Parse
__builtin_classify_type call with typename as argument.
gcc/cp/
* parser.cc (cp_parser_postfix_expression): Parse
__builtin_classify_type call with typename as argument.
* pt.cc (tsubst_copy_and_build): Handle __builtin_classify_type
with dependent typename as argument.
gcc/testsuite/
* c-c++-common/builtin-classify-type-1.c: New test.
* g++.dg/ext/builtin-classify-type-1.C: New test.
* g++.dg/ext/builtin-classify-type-2.C: New test.
* gcc.dg/builtin-classify-type-1.c: New test.
gcc/builtins.cc
gcc/builtins.h
gcc/c/c-parser.cc
gcc/cp/parser.cc
gcc/cp/pt.cc
gcc/doc/extend.texi
gcc/testsuite/c-c++-common/builtin-classify-type-1.c [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin-classify-type-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/builtin-classify-type-2.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/builtin-classify-type-1.c [new file with mode: 0644]