[PATCH] Implement Abbreviated Template Syntax and Enhanced-Auto deduction from the Concepts TS.

Faisal Vali faisalv at gmail.com
Sun Feb 22 20:07:26 PST 2015


Hi rsmith,

This patch implements the abbreviated template syntax and enhanced-auto deduction as described in the concepts TS.

Abbreviated Template Syntax:
  void f(auto) ==> template<class T> void f(T); 

Enhanced-Auto Deduction:
  pair<auto, auto> f();
  vector<auto> v = vector<int>();

Are these features OK to add to clang?  

If so, here are some notes on the implementation strategy:
  (-) Because it is not trivial to determine the final template index of each 'auto' during the initial parse, until the full declarator has been parsed, such as in a construct like the following:
    void f(auto (auto)->pair<auto, auto>) 
    ... Note, the first 'auto' does not represent a template type, and we don't know that till we have parsed the full declarator, so we can't eagerly assign indices to each auto unless the entire declarator has been parsed.

  (-) In order to signify an 'auto' as an abbreviated template parameter, it has to start its life as a dependent type (this way when it is refered to in subsequent constructs such as trailing return type etc, it behaves correctly), whereas an 'auto' that shall be deduced from its initializer starts its life as a non-dependent type (although it may later get deduced to a dependent type contingent upon its initializer for e.g.)
  (-) Once a function declarator can have its type be determined, then do we take any explicitly provided template parameter lists into account, determining if they belong to the current function or a potentially enclosing class template, and then normalize the type of the abbreviated function, replacing every auto (ignoring 'auto's that denote a trailing return type), in order of appearance with a corresponding template parameter type or pack.
  (-) In order to process constructs such as the following (and assign the correct template parameter depth to the generic lambda):
    void foo(int (*)(int) = [](auto a) { return a; }, auto b = 3); 
    ... all default arguments have to be parsed after the parameter declaration clause has been parsed.
  
  (-) An Index member has been added to the AutoType - and while it is used to generate distinct pointers to each auto type within a declarator, so that we know which 'auto' we are subsituting into, the canonical type of an auto type is always its '0' index counterpart - this canonicalization facilitates comparison of autos and merging of declarations.
  
More notes on implementation as time permits, if needed.

Please see test/cxx/auto (which will probably need to be moved, if this patch is ever approved for commit) for further examples.

Would appreciate any useful feedback.

Thanks!

http://reviews.llvm.org/D7822

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Parse/Parser.h
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/Scope.h
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  include/clang/Sema/Template.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/NestedNameSpecifier.cpp
  lib/AST/TemplateBase.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/Parse/ParseCXXInlineMethods.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseTemplate.cpp
  lib/Parse/Parser.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaLambda.cpp
  lib/Sema/SemaStmt.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Sema/SemaTemplateVariadic.cpp
  lib/Sema/SemaType.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/CXX/auto/cxx1z-abbreviated-templates.cpp
  test/CXX/auto/cxx1z-auto-vars-generalized.cpp
  test/CXX/drs/dr6xx.cpp
  test/Parser/cxx11-templates.cpp
  test/SemaCXX/cxx1y-deduced-return-type.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7822.20487.patch
Type: text/x-patch
Size: 193612 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150223/cc5de3ae/attachment.bin>


More information about the cfe-commits mailing list