summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplateDeduction.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* 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
* PR9023: A template template parameter whose template parameter list contains anRichard Smith2012-09-071-1/+1
| | | | | | | | | | | | | unexpanded parameter pack is a pack expansion. Thus, as with a non-type template parameter which is a pack expansion, it needs to be expanded early into a fixed list of template parameters. Since the expanded list of template parameters is not itself a parameter pack, it is permitted to appear before the end of the template parameter list, so also remove that restriction (for both template template parameter pack expansions and non-type template parameter pack expansions). llvm-svn: 163369
* Fix a bunch of -Wdocumentation warnings.Dmitri Gribenko2012-08-231-2/+0
| | | | llvm-svn: 162452
* Fix undefined behavior: member function calls where 'this' is a null pointer.Richard Smith2012-08-231-1/+5
| | | | llvm-svn: 162430
* When performing the deduced/actual argument type check for C++Douglas Gregor2012-07-181-0/+10
| | | | | | | | [temp.deduct.call]p4 under Objective-C++ ARC, make sure to adjust the qualifiers to introduce the implicit strong lifetime when needed. Fixes <rdar://problem/11825671>. llvm-svn: 160412
* PR13365: Fix code which was trying to treat an array of DeducedTemplateArgumentRichard Smith2012-07-161-5/+10
| | | | | | | | as an array of its base class TemplateArgument. Switch the const TemplateArgument* parameters of InstantiatingTemplate's constructors to ArrayRef<TemplateArgument> to prevent this from happening again in the future. llvm-svn: 160245
* PR13136:Richard Smith2012-07-091-3/+11
| | | | | | | | | | | | | | | * When substituting a reference to a non-type template parameter pack where the corresponding argument is a pack expansion, transform into an expression which contains an unexpanded parameter pack rather than into an expression which contains a pack expansion. This causes the SubstNonTypeTemplateParmExpr to be inside the PackExpansionExpr, rather than outside, so the expression still looks like a pack expansion and can be deduced. * Teach MarkUsedTemplateParameters that we can deduce a reference to a template parameter if it's wrapped in a SubstNonTypeTemplateParmExpr (such nodes are added during alias template substitution). llvm-svn: 159922
* PR13243: When deducing a non-type template parameter which is specified as anRichard Smith2012-07-081-2/+11
| | | | | | | | expression, skip over any SubstNonTypeTemplateParmExprs which alias templates may have inserted before checking for a DeclRefExpr referring to a non-type template parameter declaration. llvm-svn: 159909
* PR13293: Defer deduction of an auto type with a dependent declarator, such ↵Richard Smith2012-07-081-4/+39
| | | | | | as "auto (*f)(T t)". llvm-svn: 159908
* Documentation cleanup: making \param docs match the code.James Dennett2012-06-221-2/+2
| | | | llvm-svn: 158982
* Diagnostics cleanup: Fixing \params to match the code.James Dennett2012-06-221-3/+3
| | | | llvm-svn: 158981
* Still more Doxygen documentation fixes:James Dennett2012-06-141-2/+2
| | | | | | | | * Escape #, < and @ symbols where Doxygen would try to interpret them; * Fix several function param documentation where names had got out of sync; * Delete param documentation referring to parameters that no longer exist. llvm-svn: 158472
* Plug a long standing memory leak in TemplateArgument.Benjamin Kramer2012-06-071-5/+6
| | | | | | | | | | | | | | | The integral APSInt value is now stored in a decomposed form and the backing store for large values is allocated via the ASTContext. This way its not leaked as TemplateArguments are never destructed when they are allocated in the ASTContext. Since the integral data is immutable it is now shared between instances, making copying TemplateArguments a trivial operation. Currently getting the integral data out of a TemplateArgument requires creating a new APSInt object. This is cheap when the value is small but can be expensive if it's not. If this turns out to be an issue a more efficient accessor could be added. llvm-svn: 158150
OpenPOWER on IntegriCloud