llvm-project/clang/test/CXX
Faisal Vali fd5277c063 Implement a rudimentary form of generic lambdas.
Specifically, the following features are not included in this commit:
  - any sort of capturing within generic lambdas 
  - nested lambdas
  - conversion operator for captureless lambdas
  - ensuring all visitors are generic lambda aware


As an example of what compiles:

template <class F1, class F2>
struct overload : F1, F2 {
    using F1::operator();
    using F2::operator();
    overload(F1 f1, F2 f2) : F1(f1), F2(f2) { }
  };

  auto Recursive = [](auto Self, auto h, auto ... rest) {
    return 1 + Self(Self, rest...);
  };
  auto Base = [](auto Self, auto h) {
      return 1;
  };
  overload<decltype(Base), decltype(Recursive)> O(Base, Recursive);
  int num_params =  O(O, 5, 3, "abc", 3.14, 'a');

Please see attached tests for more examples.

Some implementation notes:

  - Add a new Declarator context => LambdaExprParameterContext to 
    clang::Declarator to allow the use of 'auto' in declaring generic
    lambda parameters
    
  - Augment AutoType's constructor (similar to how variadic 
    template-type-parameters ala TemplateTypeParmDecl are implemented) to 
    accept an IsParameterPack to encode a generic lambda parameter pack.
  
  - Add various helpers to CXXRecordDecl to facilitate identifying
    and querying a closure class
  
  - LambdaScopeInfo (which maintains the current lambda's Sema state)
    was augmented to house the current depth of the template being
    parsed (id est the Parser calls Sema::RecordParsingTemplateParameterDepth)
    so that Sema::ActOnLambdaAutoParameter may use it to create the 
    appropriate list of corresponding TemplateTypeParmDecl for each
    auto parameter identified within the generic lambda (also stored
    within the current LambdaScopeInfo).  Additionally, 
    a TemplateParameterList data-member was added to hold the invented
    TemplateParameterList AST node which will be much more useful
    once we teach TreeTransform how to transform generic lambdas.
    
  - SemaLambda.h was added to hold some common lambda utility
    functions (this file is likely to grow ...)
    
  - Teach Sema::ActOnStartOfFunctionDef to check whether it
    is being called to instantiate a generic lambda's call
    operator, and if so, push an appropriately prepared
    LambdaScopeInfo object on the stack.
    
  - Teach Sema::ActOnStartOfLambdaDefinition to set the
    return type of a lambda without a trailing return type
    to 'auto' in C++1y mode, and teach the return type
    deduction machinery in SemaStmt.cpp to process either
    C++11 and C++14 lambda's correctly depending on the flag.    

  - various tests were added - but much more will be needed.

A greatful thanks to all reviewers including Eli Friedman,  
James Dennett and the ever illuminating Richard Smith.  And 
yet I am certain that I have allowed unidentified bugs to creep in; 
bugs, that I will do my best to slay, once identified!

Thanks!

llvm-svn: 188977
2013-08-22 01:49:11 +00:00
..
basic Fix implementation of C11 6.2.7/4 and C++11 [dcl.array]p3: 2013-08-13 18:18:50 +00:00
class C++11: don't warn about the deprecated 'register' keyword if it's combined with 2013-06-17 01:34:01 +00:00
class.access Implement [class.friend]p11's special name lookup rules for friend declarations 2013-08-09 04:35:01 +00:00
class.derived Tests and status for core issues 1-50. 2013-05-19 07:22:38 +00:00
conv Prior to adding the new "expected-no-diagnostics" directive to VerifyDiagnosticConsumer, make the necessary adjustment to 580 test-cases which will henceforth require this new directive. 2012-10-19 12:44:48 +00:00
dcl.dcl Implement a rudimentary form of generic lambdas. 2013-08-22 01:49:11 +00:00
dcl.decl Fix implementation of C11 6.2.7/4 and C++11 [dcl.array]p3: 2013-08-13 18:18:50 +00:00
drs Sema: Diagnose explicitly bound unresolved member expressions decaying into pointers to function type 2013-08-01 06:13:59 +00:00
except C++1y constexpr extensions, round 1: Allow most forms of declaration and 2013-04-22 15:31:51 +00:00
expr Implement a rudimentary form of generic lambdas. 2013-08-22 01:49:11 +00:00
lex Integers which are too large should be an error. 2013-07-23 00:25:18 +00:00
over Don't produce duplicate notes if we have deduction failure notes when resolving 2013-08-14 00:00:44 +00:00
special Implement [class.friend]p11's special name lookup rules for friend declarations 2013-08-09 04:35:01 +00:00
stmt.stmt Add -Wdeprecated warnings and fixits for things deprecated in C++11: 2013-06-13 02:02:51 +00:00
temp Bug fix: disallow a variable template to be redeclared as a non-templated variable 2013-08-14 03:09:19 +00:00