[PATCH] D134286: [C2x] implement typeof and typeof_unqual

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 20 08:53:24 PDT 2022


aaron.ballman created this revision.
aaron.ballman added reviewers: erichkeane, jyknight, rsmith, rjmccall, clang-language-wg.
Herald added a subscriber: martong.
Herald added a reviewer: shafik.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

This implements WG14 N2927 and WG14 N2930, which together define the feature for `typeof` and `typeof_unqual`, which get the type of their argument as either fully qualified or fully unqualified. The argument to either operator is either a type name or an expression. If given a type name, the type information is pulled directly from the given name. If given an expression, the type information is pulled from the expression. Recursive use of these operators is allowed and has the expected behavior (the innermost operator is resolved to a type, and that's used to resolve the next layer of typeof specifier, until a fully resolved type is determined.

Note, we already supported `typeof` in GNU mode as a non-conforming extension and we are *not* exposing `typeof_unqual` as a non-conforming extension in that mode, nor are we exposing `typeof` or `typeof_unqual` as a nonconforming extension in other language modes. The GNU variant of `typeof` supports a form where the parentheses are elided from the operator when given an expression (e.g., `typeof 0 i = 12;`). When in C2x mode, we do not support this extension.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134286

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/C/C2x/n2927.c
  clang/test/C/C2x/n2927_2.c
  clang/test/C/C2x/n2930.c
  clang/test/Lexer/keywords_test.c
  clang/test/Parser/c2x-typeof-ext-warns.c
  clang/test/Parser/c2x-typeof.c
  clang/test/Sema/c2x-typeof.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134286.461581.patch
Type: text/x-patch
Size: 46590 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220920/2780bf13/attachment-0001.bin>


More information about the cfe-commits mailing list