summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplateDeduction.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Implement partial ordering of class template partial specializationsDouglas Gregor2011-01-111-6/+31
| | | | | | | | | | | | | | | | | | | | | | and function templates that contain variadic templates. This involves three small-ish changes: (1) When transforming a pack expansion, if the transformed argument still contains unexpanded parameter packs, build a pack expansion. This can happen during the substitution that occurs into class template partial specialiation template arguments during partial ordering. (2) When performing template argument deduction where the argument is a pack expansion, match against the pattern of that pack expansion. (3) When performing template argument deduction against a non-pack parameter, or a non-expansion template argument, deduction fails if the argument itself is a pack expansion (C++0x [temp.deduct.type]p22). llvm-svn: 123279
* Implement C++ [temp.func.order]p5 more directly, by passing down theDouglas Gregor2011-01-111-149/+145
| | | | | | | | | number of explicit call arguments. This actually fixes an erroneous test for [temp.deduct.partial]p11, where we were considering parameters corresponding to arguments beyond those that were explicitly provided. llvm-svn: 123244
* Implement the last bullet of [temp.deduct.type]p5 and part of the lastDouglas Gregor2011-01-111-1/+13
| | | | | | | | | sentence of [temp.deduct.call]p1, both of which concern the non-deducibility of parameter packs not at the end of a parameter-type-list. The latter isn't fully implemented yet; see the new FIXME. llvm-svn: 123210
* Implement more of C++0x [temp.arg.explicit]p9, allowing extension ofDouglas Gregor2011-01-101-9/+6
| | | | | | | | | pack expansions in template argument lists and function parameter lists. The implementation of this paragraph should be complete *except* for cases where we're substituting into one of the unexpanded packs in a pack expansion; that's a general issue I haven't solved yet. llvm-svn: 123188
* Repent for my copy-and-paste sins, factoring out the code that formsDouglas Gregor2011-01-101-108/+70
| | | | | | | argument packs from a set of deduced arguments, then checks that those argument packs match previously-deduced argument packs. llvm-svn: 123182
* Factor out the code to set up template argument deduction for a set ofDouglas Gregor2011-01-101-50/+40
| | | | | | | template argument packs. This also ensures that explicitly-specified template arguments get properly represented in those cases. llvm-svn: 123180
* Work-in-progress implementation of C++0x [temp.arg.explicit]p9, whichDouglas Gregor2011-01-101-25/+95
| | | | | | | | | | | | | | | | | | | | | | | | | | allows an argument pack determines via explicit specification of function template arguments to be extended by further, deduced arguments. For example: template<class ... Types> void f(Types ... values); void g() { f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int } There are a number of FIXMEs in here that indicate places where we need to implement + test retained expansions, plus a number of other places in deduction where we need to correctly cope with the explicitly-specified arguments when deducing an argument pack. Furthermore, it appears that the RecursiveASTVisitor needs to be auditied; it's missing some traversals (especially w.r.t. template arguments) that cause it not to find unexpanded parameter packs when it should. The good news, however, is that the tr1::tuple implementation now works fully, and the tr1::bind example (both from N2080) is actually working now. llvm-svn: 123163
* Implement substitution of a function parameter pack for its set ofDouglas Gregor2011-01-071-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | instantiated function parameters, enabling instantiation of arbitrary pack expansions involving function parameter packs. At this point, we can now correctly compile a simple, variadic print() example: #include <iostream> #include <string> void print() {} template<typename Head, typename ...Tail> void print(const Head &head, const Tail &...tail) { std::cout << head; print(tail...); } int main() { std::string hello = "Hello"; print(hello, ", world!", " ", 2011, '\n'); } llvm-svn: 123000
* Factor out the template transformation of a sequence of functionDouglas Gregor2011-01-071-13/+5
| | | | | | | | | parameters into parameter types, so that substitution of explicitly-specified function template arguments uses the same path. This enables the use of explicitly-specified function template arguments with variadic templates. llvm-svn: 122986
* Implement template argument deduction from a call to a functionDouglas Gregor2011-01-061-89/+239
| | | | | | | | | | | | template whose last parameter is a parameter pack. This allows us to form a call to, e.g., template<typename ...Args1, typename ...Args2> void f(std::pair<Args1, Args2> ...pairs); given zero or more instances of "pair". llvm-svn: 122973
* Fast-path an arity check when performing template argument deduction that ↵Douglas Gregor2011-01-051-2/+6
| | | | | | compares two parameter-type-lists. No functionality change. llvm-svn: 122928
* Initial implementation of function parameter packs. This implementation allows:Douglas Gregor2011-01-051-44/+218
| | | | | | | | | | | | | | 1) Declaration of function parameter packs 2) Instantiation of function parameter packs within function types. 3) Template argument deduction of function parameter packs when matching two function types. We're missing all of the important template-instantiation logic for function template definitions, along with template argument deduction from the argument list of a function call, so don't even think of trying to use these for real yet. llvm-svn: 122926
* Propagate the "deduced from array bound" bit when comparing deducedDouglas Gregor2011-01-051-5/+5
| | | | | | template argument packs. Plus, remove a FIXME that I fixed yesterday. llvm-svn: 122903
* When we're converting deduced template arguments to the type of theDouglas Gregor2011-01-051-3/+27
| | | | | | | corresponding template parameter, make sure that prior converted template arguments are available for substitution. llvm-svn: 122902
* Replace the representation of template template argument packDouglas Gregor2011-01-051-10/+28
| | | | | | | | | | | | | expansions with something that is easier to use correctly: a new template argment kind, rather than a bit on an existing kind. Update all of the switch statements that deal with template arguments, fixing a few latent bugs in the process. I"m happy with this representation, now. And, oh look! Template instantiation and deduction work for template template argument pack expansions. llvm-svn: 122896
* Add semantic analysis for the creation of and an AST representationDouglas Gregor2011-01-051-3/+4
| | | | | | | | | | | | | | | | | | | | | for template template argument pack expansions. This allows fun such as: template<template<class> class ...> struct apply_impl { /*...*/ }; template<template<class> class ...Metafunctions> struct apply { typedef typename apply_impl<Metafunctions...>::type type; }; However, neither template argument deduction nor template instantiation is implemented for template template argument packs, so this functionality isn't useful yet. I'll probably replace the encoding of template template argument pack expansions in TemplateArgument so that it's harder to accidentally forget about the expansion. However, this is a step in the right general direction. llvm-svn: 122890
* Many of the built-in operator candidates introduced into overloadDouglas Gregor2011-01-051-3/+1
| | | | | | | resolution require that the pointed-to type be an object type, but we weren't filtering out non-object types. Do so, fixing PR7851. llvm-svn: 122853
* Eliminate some completely useless code that attempted to perform someDouglas Gregor2011-01-041-32/+0
| | | | | | | | | | conversions on the substituted non-type template arguments of a class template partial specialization. C++ [temp.class.spec]p8 actually prohibits all of the cases where this code would have fired. Hey, it's better than having to deal with variadic templates here! llvm-svn: 122852
* Improve our handling of non-type template parameters in partialDouglas Gregor2011-01-041-115/+160
| | | | | | | | | | | | | specializations. We weren't dealing with any of the cases where the type of the non-type template argument differs from the type of the corresponding template parameter in the primary template. We would think that the template parameter in the partial specialization was not deducible (and warn about it, incorrectly), then fail to convert a deduced parameter to the type of the template parameter in the partial specialization (which may involve truncation, among other things). Fixes PR8905. llvm-svn: 122851
* Remove an unnecessary FIXME for variadic templatesDouglas Gregor2011-01-041-2/+0
| | | | llvm-svn: 122848
* Minor cleanups for template argument deduction in the presence ofDouglas Gregor2011-01-041-10/+3
| | | | | | variadic templates. No functionality change. llvm-svn: 122847
* Improve the checking of deduced template arguments stored within template ↵Douglas Gregor2011-01-041-40/+71
| | | | | | argument packs when finishing template argument deduction for a function template llvm-svn: 122843
* Implement support for pack expansions whose pattern is a non-typeDouglas Gregor2011-01-031-0/+4
| | | | | | | | | | | | | | | | | template argument (described by an expression, of course). For example: template<int...> struct int_tuple { }; template<int ...Values> struct square { typedef int_tuple<(Values*Values)...> type; }; It also lays the foundation for pack expansions in an initializer-list. llvm-svn: 122751
* Fix a thinko in a helper routine for template argument deduction thatDouglas Gregor2010-12-241-4/+4
| | | | | | | | caused an assertion when dealing with non-type template parameter packs. Add some tests for deduction and instantiation of non-type template parameter packs. llvm-svn: 122534
* Implement the part of C++0x [temp.arg.explicit]p3 that pertains toDouglas Gregor2010-12-231-1/+11
| | | | | | | | | | | | parameter packs. In particular, a parameter pack not otherwise deduced is deduced to an empty parameter pack. The C++0x wording here is a bit unfortunate; this should really only apply to function templates, and it mentions "trailing" parameter packs, which doesn't really make sense in the context of function templates. Will file a core issue separately. llvm-svn: 122463
* Implement the rest of C++0x [temp.deduct.type]p9, which specifies thatDouglas Gregor2010-12-231-3/+57
| | | | | | | | the presence of a pack expansion anywhere except at the end of a template-argument-list causes the entire template-argument-list to be a non-deduced context. llvm-svn: 122461
* Be paranoid about NULL size expressions in dependently-sized array typesDouglas Gregor2010-12-221-3/+4
| | | | llvm-svn: 122454
* Unify the consistency checking for deduced template arguments into aDouglas Gregor2010-12-221-125/+212
| | | | | | | | | single routine. Extend that routine to handle consistency checking for template argument packs, so that we can compare the deduced packs for template parameter packs across different pack expansions. llvm-svn: 122452
* Implement template argument deduction for pack expansions whoseDouglas Gregor2010-12-221-21/+154
| | | | | | | | | | | pattern is a template argument, which involves repeatedly deducing template arguments using the pattern of the pack expansion, then bundling the resulting deductions into an argument pack. We can now handle a variety of simple list-handling metaprograms using variadic templates. See, e.g., the new "count" metaprogram. llvm-svn: 122439
* When performing template argument deduction where the argument is aDouglas Gregor2010-12-221-12/+15
| | | | | | | | | | dependent template specialization type, the number of template arguments need not match precisely. Rather than checking the number of arguments eagerly (which does not consider argument packs), let the deduction routine for template argument lists cope with too many/too few arguments. llvm-svn: 122425
* Implicitly expand argument packs when performing template argumentDouglas Gregor2010-12-221-33/+98
| | | | | | | | | | | | deduction. Unify all of the looping over template arguments for deduction purposes into a single place, where argument pack expansion occurs; this is also the hook for deducing from pack expansions, which itself is not yet implemented. For now, at least we can handle a basic "count" metafunction written with variadics. See the new test for the formulation that works. llvm-svn: 122418
* Clean up the handling of template argument packs, especially in theDouglas Gregor2010-12-201-1/+2
| | | | | | | area of printing template arguments. The functionality changes here are limited to cases of variadic templates that aren't yet enabled. llvm-svn: 122250
* Introduce a new type, PackExpansionType, to capture types that areDouglas Gregor2010-12-201-0/+6
| | | | | | | | | | | | | | | | | | | | pack expansions, e.g. given template<typename... Types> struct tuple; template<typename... Types> struct tuple_of_refs { typedef tuple<Types&...> types; }; the type of the "types" typedef is a PackExpansionType whose pattern is Types&. This commit introduces support for creating pack expansions for template type arguments, as above, but not for any other kind of pack expansion, nor for any form of instantiation. llvm-svn: 122223
* It's kindof silly that ExtQuals has an ASTContext&, and we can use thatJohn McCall2010-12-101-1/+3
| | | | | | | | | | space better. Remove this reference. To make that work, change some APIs (most importantly, getDesugaredType()) to take an ASTContext& if they need to return a QualType. Simultaneously, diminish the need to return a QualType by introducing some useful APIs on SplitQualType, which is just a std::pair<const Type *, Qualifiers>. llvm-svn: 121478
* PR5207: Change APInt methods trunc(), sext(), zext(), sextOrTrunc() andJay Foad2010-12-071-2/+2
| | | | | | | | zextOrTrunc(), and APSInt methods extend(), extOrTrunc() and new method trunc(), to be const and to return a new value instead of modifying the object in place. llvm-svn: 121121
* Switch a lot of call-sites over to using the new value-kind calculations.John McCall2010-11-241-1/+1
| | | | llvm-svn: 120084
* Implement C++0x [temp.func.order]p3 (aka DR532) properly. InDouglas Gregor2010-11-151-5/+33
| | | | | | | | | | | | | particular, we only add the implement object parameter type if only one of the function templates is a non-static member function template. Moreover, since this DR differs from existing practice in C++98/03, this commit implements the existing practice (which ignores the first parameter of the function template that is not the non-static member function template) in C++98/03 mode. llvm-svn: 119145
* Implement C++ [over.match.funcs]p4 as it concerns partial ordering ofDouglas Gregor2010-11-121-4/+40
| | | | | | function templates. Fixes PR8130. llvm-svn: 118944
* Remove broken support for variadic templates, along with the variousDouglas Gregor2010-11-071-25/+26
| | | | | | | | | | | | | abstractions (e.g., TemplateArgumentListBuilder) that were designed to support variadic templates. Only a few remnants of variadic templates remain, in the parser (parsing template type parameter packs), AST (template type parameter pack bits and TemplateArgument::Pack), and Sema; these are expected to be used in a future implementation of variadic templates. But don't get too excited about that happening now. llvm-svn: 118385
* When determining which template partial specialization is more specialized,Argyrios Kyrtzidis2010-11-051-2/+8
| | | | | | make sure to setup the instantiation stack. Fixes rdar://8620775 & http://llvm.org/PR8234 llvm-svn: 118314
* When performing template argument deduction against a template-id,Douglas Gregor2010-11-021-2/+9
| | | | | | | only keep deduction results for successful deductions, so that they can be compared against each other. Fixes PR8462, from Richard Smith! llvm-svn: 117983
* No really, we don't have a retain/release system for statements/expressionsJohn McCall2010-10-261-1/+1
| | | | | | anymore. llvm-svn: 117357
* Introduce support for emitting diagnostics (warnings + their notes)Douglas Gregor2010-10-121-4/+18
| | | | | | | | | | | | | | | that are suppressed during template argument deduction. This change queues diagnostics computed during template argument deduction. Then, if the resulting function template specialization or partial specialization is chosen by overload resolution or partial ordering (respectively), we will emit the queued diagnostics at that point. This addresses most of PR6784. However, the check for unnamed/local template arguments (which existed before this change) is still only skin-deep, and needs to be extended to look deeper into types. It must be improved to finish PR6784. llvm-svn: 116373
* Enter the context of the declared function template when performingJohn McCall2010-10-121-2/+6
| | | | | | | deduction and the final substitution, but not while substituting the explicit template arguments. Fixes rdar://problem/8537391 llvm-svn: 116332
* When finalizing a function template specialization following templateDouglas Gregor2010-10-121-7/+4
| | | | | | | | | | argument deduction, make sure to check the correctness of deduced template type arguments (which we had previously skipped) along with other kinds of template arguments. This fixes part of PR6784, but we're still swallowing the extension warning about unnamed/local template arguments. llvm-svn: 116327
* When performing template argument deduction of a function templateDouglas Gregor2010-09-291-4/+14
| | | | | | | | against a function type, be sure to check the type of the resulting function template specialization against the desired function type after substituting the deduced/defaulted template arguments. Fixes PR8196. llvm-svn: 115086
* Perform the function-to-pointer adjustment during template argumentDouglas Gregor2010-08-301-31/+43
| | | | | | | | | deduction where the parameter is a function reference, function pointer, or member function pointer and the argument is an overloaded function. Fixes <rdar://problem/8360106>, a template argument deduction issue found by Boost.Filesystem. llvm-svn: 112523
* When perform exact-qualifier-match template argument deduction,John McCall2010-08-281-1/+24
| | | | | | | properly account for the possibility that certain opaque types might be more qualified than they appear. Fixes PR7708. llvm-svn: 112390
* Propagate whether an id-expression is the immediate argument ofJohn McCall2010-08-271-8/+17
| | | | | | | | | | | | | | | | | | | an '&' expression from the second caller of ActOnIdExpression. Teach template argument deduction that an overloaded id-expression doesn't give a valid type for deduction purposes to a non-static member function unless the expression has the correct syntactic form. Teach ActOnIdExpression that it shouldn't try to create implicit member expressions for '&function', because this isn't a permitted form of use for member functions. Teach CheckAddressOfOperand to diagnose these more carefully. Some of these cases aren't reachable right now because earlier diagnostics interrupt them. llvm-svn: 112258
* Move more stuff out of Sema.h.John McCall2010-08-251-18/+21
| | | | llvm-svn: 112026
OpenPOWER on IntegriCloud