Skip to content

Commit cc308f6

Browse files
authored
[clang] Support __typeof_unqual__ in all C modes (llvm#87392)
GCC has added __typeof_unqual__ to allow typeof_unqual to be used in all C modes (not just C23 and newer), similar to __typeof__ and typeof. https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=607d9d50ee44163cee621cd991600acaf78c2fee The Linux kernel would like to start using __typeof_unqual__ to strip type qualifiers such as address spaces from inputs to macros but cannot switch to C23 due to compiler version requirements. Match GCC and allow __typeof_unqual__ in all C modes. Closes: llvm#76423 Link: https://lore.kernel.org/CAFULd4YG21NdF_qNVBGDtXO6xnaYFeRPvKicB=gpgUUqYE=4jw@mail.gmail.com/
1 parent 5b95931 commit cc308f6

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ Non-comprehensive list of changes in this release
193193
with support for any unsigned integer type. Like the previous builtins, these
194194
new builtins are constexpr and may be used in constant expressions.
195195

196+
- ``__typeof_unqual__`` is available in all C modes as an extension, which behaves
197+
like ``typeof_unqual`` from C23, similar to ``__typeof__`` and ``typeof``.
198+
196199
New Compiler Flags
197200
------------------
198201
- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and

clang/include/clang/Basic/TokenKinds.def

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -665,28 +665,30 @@ KEYWORD(__kindof , KEYOBJC)
665665

666666
// Alternate spelling for various tokens. There are GCC extensions in all
667667
// languages, but should not be disabled in strict conformance mode.
668-
ALIAS("__alignof__" , __alignof , KEYALL)
669-
ALIAS("__asm" , asm , KEYALL)
670-
ALIAS("__asm__" , asm , KEYALL)
671-
ALIAS("__attribute__", __attribute, KEYALL)
672-
ALIAS("__complex" , _Complex , KEYALL)
673-
ALIAS("__complex__" , _Complex , KEYALL)
674-
ALIAS("__const" , const , KEYALL)
675-
ALIAS("__const__" , const , KEYALL)
676-
ALIAS("__decltype" , decltype , KEYCXX)
677-
ALIAS("__imag__" , __imag , KEYALL)
678-
ALIAS("__inline" , inline , KEYALL)
679-
ALIAS("__inline__" , inline , KEYALL)
680-
ALIAS("__nullptr" , nullptr , KEYCXX)
681-
ALIAS("__real__" , __real , KEYALL)
682-
ALIAS("__restrict" , restrict , KEYALL)
683-
ALIAS("__restrict__" , restrict , KEYALL)
684-
ALIAS("__signed" , signed , KEYALL)
685-
ALIAS("__signed__" , signed , KEYALL)
686-
ALIAS("__typeof" , typeof , KEYALL)
687-
ALIAS("__typeof__" , typeof , KEYALL)
688-
ALIAS("__volatile" , volatile , KEYALL)
689-
ALIAS("__volatile__" , volatile , KEYALL)
668+
ALIAS("__alignof__" , __alignof , KEYALL)
669+
ALIAS("__asm" , asm , KEYALL)
670+
ALIAS("__asm__" , asm , KEYALL)
671+
ALIAS("__attribute__" , __attribute , KEYALL)
672+
ALIAS("__complex" , _Complex , KEYALL)
673+
ALIAS("__complex__" , _Complex , KEYALL)
674+
ALIAS("__const" , const , KEYALL)
675+
ALIAS("__const__" , const , KEYALL)
676+
ALIAS("__decltype" , decltype , KEYCXX)
677+
ALIAS("__imag__" , __imag , KEYALL)
678+
ALIAS("__inline" , inline , KEYALL)
679+
ALIAS("__inline__" , inline , KEYALL)
680+
ALIAS("__nullptr" , nullptr , KEYCXX)
681+
ALIAS("__real__" , __real , KEYALL)
682+
ALIAS("__restrict" , restrict , KEYALL)
683+
ALIAS("__restrict__" , restrict , KEYALL)
684+
ALIAS("__signed" , signed , KEYALL)
685+
ALIAS("__signed__" , signed , KEYALL)
686+
ALIAS("__typeof" , typeof , KEYALL)
687+
ALIAS("__typeof__" , typeof , KEYALL)
688+
ALIAS("__typeof_unqual" , typeof_unqual, KEYALL)
689+
ALIAS("__typeof_unqual__", typeof_unqual, KEYALL)
690+
ALIAS("__volatile" , volatile , KEYALL)
691+
ALIAS("__volatile__" , volatile , KEYALL)
690692

691693
// Type nullability.
692694
KEYWORD(_Nonnull , KEYALL)

clang/test/Parser/c2x-typeof-ext-warns.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
// standards before C23, and Clang has followed suit. Neither compiler exposes
1313
// 'typeof_unqual' as a non-conforming extension.
1414

15-
// Show what happens with the underscored version of the keyword, which is a
16-
// conforming extension.
15+
// Show what happens with the underscored version of the keywords, which are
16+
// conforming extensions.
1717
__typeof__(int) i = 12;
18+
__typeof(int) _i = 12;
19+
__typeof_unqual__(int) u = 12;
20+
__typeof_unqual(int) _u = 12;
1821

1922
// Show what happens with a regular 'typeof' use.
2023
typeof(i) j = 12; // c11-error {{expected function body after function declarator}} \

clang/test/SemaCXX/typeof_unqual.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
3+
typeof_unqual(int) u = 12; // expected-error {{expected function body after function declarator}}
4+
__typeof_unqual(int) _u = 12;
5+
__typeof_unqual__(int) __u = 12;

0 commit comments

Comments
 (0)