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

Nicholas Allegra via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 14 23:55:48 PDT 2015


comex updated the summary for this revision.
comex updated this revision to Diff 34787.
comex added a comment.

Per vsk:

- Changed to an explicit switch, and changed ContainsPlaceholderType logic.

Note: Currently, GetDeclSpecTypeForDeclarator determines ContainsPlaceholderType at two different levels depending on the context: usually it calls containsPlaceholderType on the DeclSpec, but for conversion methods it searches the Type itself using getContainedAutoType.  This confused me, because I can't come up with any conversion method declaration that would actually yield different answers for those predicates, given the definition of getContainedAutoType - at least that wouldn't generate an error elsewhere.  (They're different in the case of an auto lambda parameter, in which case the AutoType has already been converted to a dependent template type, but that's not a conversion.)  The old patch implicitly assumed containsPlaceholderType was true when it checked getTypeSpecType; I could avoid this by determining which auto keyword is being used a different way in the conversion case, but since that would be really ugly, I went ahead and removed ContainsPlaceholderType in favor of always calling containsPlaceholderType, effectively partially reverting SVN revision 181108.  This might be wrong.

For example, these all still properly fail with this patch:

  template <typename T> struct F {};
  struct A {
    operator auto() {}
    operator auto*() {}
    operator auto*() {}
    operator F<auto>() {}
    operator auto() -> auto {}
    operator __typeof__(auto(*)())() {}
    operator __typeof__([](auto){})() {} // bad error though (unaffected by patch)
  };

I did come up with this snippet which trips an assertion in stock Clang (also unaffected by this patch):

  typedef __typeof__(auto()) *T;
  T lol = (T) 2;

...and here's another one:

  typedef &decltype(auto)::x T;

I guess I should report these separately.

- Added error for using `__auto_type` with a bitfield in C; since it was easy, I also added the same for typeof, despite it not being strictly related.

Per rsmith:

- Changed enum struct to enum class, and AutoTypeExt to GNUAutoType.
- As far as I understand, having distinguishable values profile the same would break uniquing - in this case, that done in getAutoType().  In theory, mangling shouldn't be a problem because the cases where 'auto' ends up being mangled shouldn't be allowed with `__auto_type`: AFAICT only C++14 (template) functions with deduced return types.  But it turns out I wasn't properly banning those, which I fixed.  I also added an assertion to the two manglers that `__auto_type` isn't encountered.
- Fixed whitespace and removed getTypePtr().

Also:

- Improved error message with code like `__auto_type x = {2, 3};` in C (previously it referred to std::initializer_list)


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/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.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/Sema/bitfield.c
  test/Sema/exprs.c
  test/SemaCXX/auto-type-from-cxx.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12686.34787.patch
Type: text/x-patch
Size: 37484 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150915/efd02945/attachment-0001.bin>


More information about the cfe-commits mailing list