summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplateDeduction.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix gcc -Wunused-but-set-variable warning in r191634.Patrik Hagglund2013-10-021-5/+2
| | | | llvm-svn: 191817
* SemaTemplateDeduction.cpp: Suppress a warning. [-Wunused-variable]NAKAMURA Takumi2013-09-301-1/+1
| | | | llvm-svn: 191648
* Fix windows newlines :(Faisal Vali2013-09-291-133/+133
| | | | llvm-svn: 191641
* Implement conversion to function pointer for generic lambdas without captures.Faisal Vali2013-09-291-12/+163
| | | | | | | | | | | | | | | | The general strategy is to create template versions of the conversion function and static invoker and then during template argument deduction of the conversion function, create the corresponding call-operator and static invoker specializations, and when the conversion function is marked referenced generate the body of the conversion function using the corresponding static-invoker specialization. Similarly, Codegen does something similar - when asked to emit the IR for a specialized static invoker of a generic lambda, it forwards emission to the corresponding call operator. This patch has been reviewed in person both by Doug and Richard. Richard gave me the LGTM. A few minor changes: - per Richard's request i added a simple check to gracefully inform that captures (init, explicit or default) have not been added to generic lambdas just yet (instead of the assertion violation). - I removed a few lines of code that added the call operators instantiated parameters to the currentinstantiationscope. Not only did it not handle parameter packs, but it is more relevant in the patch for nested lambdas which will follow this one, and fix that problem more comprehensively. - Doug had commented that the original implementation strategy of using the TypeSourceInfo of the call operator to create the static-invoker was flawed and allowed const as a member qualifier to creep into the type of the static-invoker. I currently kludge around it - but after my initial discussion with Doug, with a follow up session with Richard, I have added a FIXME so that a more elegant solution that involves the use of TrivialTypeSourceInfo call followed by the correct wiring of the template parameters to the functionprototypeloc is forthcoming. Thanks! llvm-svn: 191634
* Per latest drafting, switch to implementing init-captures as if by declaringRichard Smith2013-09-281-2/+6
| | | | | | and capturing a variable declaration, and complete the implementation of them. llvm-svn: 191605
* Implement a rudimentary form of generic lambdas.Faisal Vali2013-09-261-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically, the following features are not included in this commit: - any sort of capturing within generic lambdas - generic lambdas within template functions and nested within other generic lambdas - conversion operator for captureless lambdas - ensuring all visitors are generic lambda aware (Although I have gotten some useful feedback on my patches of the above and will be incorporating that as I submit those patches for commit) As an example of what compiles through this commit: 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. This patch has been reviewed by Doug and Richard. Minor changes (non-functionality affecting) have been made since both of them formally looked at it, but the changes involve removal of supernumerary return type deduction changes (since they are now redundant, with richard having committed a recent patch to address return type deduction for C++11 lambdas using C++14 semantics). Some implementation notes: - Add a new Declarator context => LambdaExprParameterContext to clang::Declarator to allow the use of 'auto' in declaring generic lambda parameters - 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 SemaType.cpp::ConvertDeclSpecToType may use it to immediately generate a template-parameter-type when 'auto' is parsed in a generic lambda parameter context. (i.e we do NOT use AutoType deduced to a template parameter type - Richard seemed ok with this approach). We encode that this template type was generated from an auto by simply adding $auto to the name which can be used for better diagnostics if needed. - 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. - various tests were added - but much more will be needed. There is obviously more work to be done, and both Richard (weakly) and Doug (strongly) have requested that LambdaExpr be removed form the CXXRecordDecl LambdaDefinitionaData in a future patch which is forthcoming. A greatful thanks to all reviewers including Eli Friedman, James Dennett, and especially the two gracious wizards (Richard Smith and Doug Gregor) who spent hours providing feedback (in person in Chicago and on the mailing lists). 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: 191453
* SemaTemplateDeduction.cpp: Prune two stray \param(s), TPOC and ↵NAKAMURA Takumi2013-09-111-6/+0
| | | | | | NumCallArguments in Sema::getMostSpecialized(). They were removed since r190444. [-Wdocumentation] llvm-svn: 190501
* PR17075: When performing partial ordering of a member function against aRichard Smith2013-09-111-40/+43
| | | | | | | | | | | non-member function, the number of arguments in the two candidate calls will be different (the non-member call will have one extra argument). We used to get confused by this, and fail to compare the last argument when testing whether the member is better, resulting in us always thinking it is, even if the non-member is more specialized in the last argument. llvm-svn: 190470
* getMostSpecialized for function template sets is never used in the context of aRichard Smith2013-09-101-3/+2
| | | | | | | call; remove its 'number of explicit arguments' and 'what kind of call' parameters. llvm-svn: 190444
* A clean-up pass, exploring the unification of traversals of class, variable ↵Larisse Voufo2013-08-231-3/+15
| | | | | | and function templates. llvm-svn: 189152
* Use pop_back_val() instead of both back() and pop_back().Robert Wilhelm2013-08-231-4/+2
| | | | | | No functionality change intended. llvm-svn: 189112
* Revert "Implement a rudimentary form of generic lambdas."Manuel Klimek2013-08-221-12/+3
| | | | | | This reverts commit 606f5d7a99b11957e057e4cd1f55f931f66a42c7. llvm-svn: 189004
* Implement a rudimentary form of generic lambdas.Faisal Vali2013-08-221-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* PR16875: The return type of a dependent function type is visible when it'sRichard Smith2013-08-141-5/+4
| | | | | | | | | | | referenced as a member of the current instantiation. In that case, deduce the type of the function to a dependent type rather than exposing an undeduced auto type to the rest of the current instantiation. The standard doesn't really say that the type is dependent in this case; I'll bring this up with CWG. llvm-svn: 188410
* Added source locs for angled parentheses in class/var template partial specs.Enea Zaffanella2013-08-101-10/+13
| | | | llvm-svn: 188134
* Omit llvm:: before ArrayRef, as we have using llvm::ArrayRef in ↵Robert Wilhelm2013-08-091-6/+4
| | | | | | include/clang/Basic/LLVM.h. llvm-svn: 188089
* A bit of clean up based on peer's feedback...Larisse Voufo2013-08-061-1/+1
| | | | llvm-svn: 187784
* Started implementing variable templates. Top level declarations should be ↵Larisse Voufo2013-08-061-1/+212
| | | | | | fully supported, up to some limitations documented as FIXMEs or TODO. Static data member templates work very partially. Static data member templates of class templates need particular attention... llvm-svn: 187762
* FIXME fix: improving diagnostics for template arguments deduction of class ↵Larisse Voufo2013-07-191-15/+10
| | | | | | | | templates and explicit specializations This patch essentially removes all the FIXMEs following calls to DeduceTemplateArguments() that want to keep track of deduction failure info. llvm-svn: 186730
* Revert "Use function overloading instead of template specialization for ↵Larisse Voufo2013-07-191-10/+15
| | | | | | | | diagnosis of bad template argument deductions." This reverts commit a730f548325756d050d4caaa28fcbffdae8dfe95. llvm-svn: 186729
* Use function overloading instead of template specialization for diagnosis of ↵Larisse Voufo2013-07-191-15/+10
| | | | | | bad template argument deductions. llvm-svn: 186727
* Introduce a typedef for the type of NewlyDeducedPacks to avoid repeating the ↵Craig Topper2013-07-081-20/+19
| | | | | | small size of the inner SmallVector. llvm-svn: 185789
* Remove 'else' after 'return'Craig Topper2013-07-081-1/+1
| | | | llvm-svn: 185787
* Function argument formatting fixes. No functional change.Craig Topper2013-07-081-6/+6
| | | | llvm-svn: 185786
* Function argument formatting fixes.Craig Topper2013-07-081-17/+19
| | | | llvm-svn: 185785
* Add typedefs for Densemaps containing SmallVectors to avoid repeating the ↵Craig Topper2013-07-051-1/+1
| | | | | | SmallVector size when creating iterators for the DenseMap. llvm-svn: 185682
* Part of PR15673: If a function template has a default argument in whichRichard Smith2013-07-041-2/+5
| | | | | | | | | substitution failed, report that as a substitution failure rather than pretending that there was no default argument. The test cases in PR15673 have exposed some pre-existing poor diagnostics here. llvm-svn: 185604
* Implement most of N3638 (return type deduction for normal functions).Richard Smith2013-05-041-15/+63
| | | | | | | Missing (somewhat ironically) is support for the new deduction rules in lambda functions, plus PCH support for return type patching. llvm-svn: 181108
* Simplify slightly.Richard Smith2013-05-041-4/+4
| | | | llvm-svn: 181092
* When deducing an 'auto' type, don't modify the type-as-written.Richard Smith2013-04-301-24/+23
| | | | llvm-svn: 180808
* Don't treat a non-deduced 'auto' type as being type-dependent. Instead, thereRichard Smith2013-04-301-39/+13
| | | | | | | | are now two distinct canonical 'AutoType's: one is the undeduced 'auto' placeholder type, and the other is a deduced-but-dependent type. All deduced-to-a-non-dependent-type cases are still non-canonical. llvm-svn: 180789
* Implement C++1y decltype(auto).Richard Smith2013-04-261-2/+22
| | | | llvm-svn: 180610
* Fix PR15291: noreturn adjustment in overload resolution for function ↵Douglas Gregor2013-04-171-16/+71
| | | | | | templates, from Alexander Zinenko! llvm-svn: 179680
* Sema: Preserve attributes on parameters in instantiated function templates.Jordan Rose2013-03-081-5/+1
| | | | | | | | | | | | | | | | | | This was causing correctness issues for ARC and the static analyzer when a function template has "consumed" Objective-C object parameters (i.e. parameters that will be released by the function before returning). The fix is threefold: (1) Actually copy over the attributes from old ParmVarDecls to new ones. (2) Have Sema::BuildFunctionType only work for building FunctionProtoTypes, which it was doing anyway. This allows us to pass an ExtProtoInfo instead of a plain ExtInfo and several flags. (3) Drop param attributes as part of StripImplicitInstantiation, which is used when an implicit instantiation is followed by an explicit one. <rdar://problem/12685622> llvm-svn: 176728
* ArrayRef-ize ASTContext::getFunctionType and Sema::BuildFunctionType.Jordan Rose2013-03-081-2/+1
| | | | | | No (intended) functionality change. llvm-svn: 176726
* Improve 'failed template argument deduction' diagnostic for the case where weRichard Smith2013-01-311-8/+14
| | | | | | | | have a direct mismatch between some component of the template and some component of the argument. The diagnostic now says what the mismatch was, but doesn't yet say which part of the template doesn't match. llvm-svn: 174039
* Replace "failed template argument deduction" diagnostic with something usefulRichard Smith2013-01-311-5/+8
| | | | | | in the one case where we've already factored out a reason code. llvm-svn: 174036
* Use 'const Decl *' throughout code completion in SemaDmitri Gribenko2013-01-231-1/+1
| | | | llvm-svn: 173277
* Once we've collected the template arguments for aDouglas Gregor2013-01-181-3/+7
| | | | | | | | partially-substituted parameter pack in a template, forget about the partially-substituted parameter pack: it is now completed. Fixes <rdar://problem/12176336>. llvm-svn: 172859
* s/CPlusPlus0x/CPlusPlus11/gRichard Smith2013-01-021-6/+6
| | | | llvm-svn: 171367
* Fix http://stackoverflow.com/questions/13521163Richard Smith2012-12-061-13/+4
| | | | | | | | | | | Don't require that, during template deduction, a template specialization type as a function parameter has at least as many template arguments as one used in a function argument (not even if the argument has been resolved to an exact type); the additional parameters might be provided by default template arguments in the template. We don't need this check, since we now implement [temp.deduct.call]p4 with an additional check after deduction. llvm-svn: 169475
* Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth2012-12-041-5/+5
| | | | | | | | | | | | | uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. llvm-svn: 169237
* SemaTemplateDeduction.cpp: Prune two obsolete descriptions. [-Wdocumentation]NAKAMURA Takumi2012-11-141-9/+0
| | | | | | | | | | | | | | | | | * getMostSpecialized() /// \param Index if non-NULL and the result of this function is non-nULL, /// receives the index corresponding to the resulting function template /// specialization. * DeduceTemplateArguments() /// \param Name the name of the function being called. This is only significant /// when the function template is a conversion function template, in which /// case this routine will also perform template argument deduction based on /// the function to which llvm-svn: 167909
* When template deduction fails on a derived class, try a template deduction onRichard Trieu2012-11-071-1/+6
| | | | | | | | | | the base class. If the base class deduction succeeds, use those results. If it fails, keep using the results from the derived class template deduction. This prevents an assertion later where the type of deduction failure doesn't match up with the template deduction info. llvm-svn: 167550
* Fix assertion failure with auto and nested initializer list; PR14272.Eli Friedman2012-11-061-2/+3
| | | | llvm-svn: 167506
* Fix the AST representation for non-type template arguments to encodeEli Friedman2012-09-261-10/+56
| | | | | | | | | | | | enough information so we can mangle them correctly in cases involving dependent parameter types. (This specifically impacts cases involving null pointers and cases involving parameters of reference type.) Fix the mangler to use this information instead of trying to scavenge it out of the parameter declaration. <rdar://problem/12296776>. llvm-svn: 164656
* Fix a small FIXME involving template partial ordering andEli Friedman2012-09-191-16/+13
| | | | | | member function templates with an rvalue ref qualifier. llvm-svn: 164267
* Fix function template partial ordering rules for static vs. non-staticEli Friedman2012-09-191-9/+12
| | | | | | functions. llvm-svn: 164263
* Remove Context argument from TemplateDeductionInfo constructor. It was no ↵Craig Topper2012-09-191-5/+5
| | | | | | longer needed after the unused Context member was removed in r164104. llvm-svn: 164196
* Don't perform template argument deduction against invalid templates;Douglas Gregor2012-09-131-0/+12
| | | | | | | it's likely to lead to a crash later on. Fixes PR12933 / <rdar://problem/11525335>. llvm-svn: 163838
OpenPOWER on IntegriCloud