[PATCH] D12686: Add support for GCC's '__auto_type' extension.

Nicholas Allegra via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 8 00:44:08 PDT 2015


comex created this revision.
comex added a subscriber: cfe-commits.
Herald added subscribers: aemerson, klimek.

Add support for GCC's '__auto_type' extension.

As per the GCC manual: https://gcc.gnu.org/onlinedocs/gcc/Typeof.html

Implemented in GCC 4.9, __auto_type is similar to C++11 auto but works in C.
The most compelling use case is for macros; the above manual page explains the
need pretty well, so I won't repeat it here.

This implementation differs from GCC's in also supporting __auto_type in C++,
treating it the same as auto.  I don't see any good reason not to, because
otherwise headers intended to be used from both languages can't use it (you
could use a define that expands to '__auto_type' or 'auto' depending on the
language, but then C++ pre-11 is broken).  However, for sanity's sake, it
prevents using __auto_type instead of auto with C++11+-specific functionality
such as 'decltype(auto)', auto arguments to lambdas, and auto before a trailing
return type.

**It also differs by allowing all of the following (by default, due to reusing
the C++ auto behavior) which GCC rejects: initializing with the value of a bit
field, using '__auto_type *', and declaring multiple variables in one
statement.  (The first of those extends a preexisting difference: GCC does not
allow typeof on a bit field, while Clang currently does.  Arguably a bug, as
the C standard prohibits using sizeof on them.)  Maybe this should be tightened
for the sake of compatibility, although it doesn't otherwise seem harmful to
allow them (the latter two, anyway).  Opinions desired.

Making this work in clang is pretty straightforward: most of the patch is only
needed to fix up diagnostics.

(This is my first patch submission, so please let me know if I've done things
wrong.)


http://reviews.llvm.org/D12686

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/DeclSpec.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseObjc.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateVariadic.cpp
  lib/Sema/SemaType.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-1y.cpp
  test/Sema/auto-type.c
  test/SemaCXX/auto-type-from-cxx.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12686.34194.patch
Type: text/x-patch
Size: 30029 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150908/4e909d0e/attachment-0001.bin>


More information about the cfe-commits mailing list