summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplateDeduction.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Access-check during template argument deduction from the context of theJohn McCall2010-04-291-3/+3
| | | | | | template decl itself, not its context. Testcase to follow; fixes selfhost. llvm-svn: 102578
* Properly switch into the declaring scope of a template when performingJohn McCall2010-04-291-0/+6
| | | | | | | | | | template argument deduction or (more importantly) the final substitution required by such deduction. Makes access control magically work in these cases. Fixes PR6967. llvm-svn: 102572
* When instantiating a function template specialization followingDouglas Gregor2010-04-281-2/+4
| | | | | | | | template argument deduction, use the lexical declaration context as the owner for friend function templates. Fixes 2 failures in Boost.Graph. llvm-svn: 102489
* Make the InjectedClassNameType the canonical type of the current instantiationJohn McCall2010-04-271-5/+13
| | | | | | | | | | | | | | | | of a class template or class template partial specialization. That is to say, in template <class T> class A { ... }; or template <class T> class B<const T*> { ... }; make 'A<T>' and 'B<const T*>' sugar for the corresponding InjectedClassNameType when written inside the appropriate context. This allows us to track the current instantiation appropriately even inside AST routines. It also allows us to compute a DeclContext for a type much more efficiently, at some extra cost every time we write a template specialization (which can be optimized, but I've left it simple in this patch). llvm-svn: 102407
* Rename TypenameType to DependentNameType in anticipation of someDouglas Gregor2010-03-311-3/+3
| | | | | | refactoring work in this area. llvm-svn: 100019
* After performing template argument deduction for a function template,Douglas Gregor2010-03-281-28/+162
| | | | | | | | | | | | | | | | | | | | check deduced non-type template arguments and template template arguments against the template parameters for which they were deduced, performing conversions as appropriate so that deduced template arguments get the same treatment as explicitly-specified template arguments. This is the bulk of PR6723. Also keep track of whether deduction of a non-type template argument came from an array bound (vs. anywhere else). With this information, we enforce C++ [temp.deduct.type]p17, which requires exact type matches when deduction deduces a non-type template argument from something that is not an array bound. Finally, when in a SFINAE context, translate the "zero sized arrays are an extension" extension diagnostic into a hard error (for better standard conformance), which was a minor part of PR6723. llvm-svn: 99734
* When deducing an integral template argument for a non-type templateDouglas Gregor2010-03-261-32/+35
| | | | | | | | | | parameter, keep the integral value exactly as it was in the source code rather than trying to convert it to the type of the non-type template parameter (which may still be dependent!). The value will then be converted to the appropriate type once we check the resulting template arguments. Fixes PR6707. llvm-svn: 99611
* Improve our handling of local instantiation scopes in two related ways:Douglas Gregor2010-03-251-7/+5
| | | | | | | | | | | | | | | - When substituting template arguments as part of template argument deduction, introduce a new local instantiation scope. - When substituting into a function prototype type, introduce a new "temporary" local instantiation scope that merges with its outer scope but also keeps track of any additions it makes, removing them when we exit that scope. Fixes PR6700, where we were getting too much mixing of local instantiation scopes due to template argument deduction that substituted results into function types. llvm-svn: 99509
* Create a new InjectedClassNameType to represent bare-word references to the John McCall2010-03-101-0/+9
| | | | | | | | | | | | | injected class name of a class template or class template partial specialization. This is a non-canonical type; the canonical type is still a template specialization type. This becomes the TypeForDecl of the pattern declaration, which cleans up some amount of code (and complicates some other parts, but whatever). Fixes PR6326 and probably a few others, primarily by re-establishing a few invariants about TypeLoc sizes. llvm-svn: 98134
* Split out types that are non-canonical unless dependent as their ownJohn McCall2010-03-011-0/+21
| | | | | | | | | | | category. Use this in a few places to eliminate unnecessary TST cases and do some future-proofing. Provide terrible manglings for typeof. Mangle decltype with some hope of accuracy. Our manglings for some of the cases covered in the testcase are different from gcc's, which I've raised as an issue with the ABI list. llvm-svn: 97523
* Thread a source location into the template-argument deduction routines. ThereJohn McCall2010-02-081-11/+12
| | | | | | | may be some other places that could take advantage of this new information, but I haven't really looked yet. llvm-svn: 95600
* Require a complete type before examining base classes during template argumentChandler Carruth2010-02-071-72/+80
| | | | | | | | | | deduction. This requires refactoring the deduction to have access to the Sema object instead of merely the ASTContext. Still leaves something to be desired due to poor source location. Fixes PR6257 and half of PR6259. llvm-svn: 95528
* Extract a common base class between UnresolvedLookupExpr andJohn McCall2010-02-021-23/+8
| | | | | | UnresolvedMemberExpr and employ it in a few places where it's useful. llvm-svn: 95072
* Implement C++ [temp.deduct.call]p6, template argument deduction for overloadedJohn McCall2010-02-021-31/+111
| | | | | | | | | | arguments. Fix a bug where incomplete explicit specializations were being passed through as legitimate. Fix a bug where the absence of an explicit specialization in an overload set was causing overall deduction to fail. Fixes PR6191. llvm-svn: 95052
* Implement access control for overloaded functions. Suppress access controlJohn McCall2010-01-271-37/+32
| | | | | | | diagnostics in "early" lookups, such as during typename checks and when building unresolved lookup expressions. llvm-svn: 94647
* After dyn_cast'ing, it generally makes sense to check the *output* ofDouglas Gregor2010-01-141-1/+1
| | | | | | the dyn_cast against NULL rather than the *input*. Fixes PR6025. llvm-svn: 93435
* When resolving a single function template specialization to aDouglas Gregor2010-01-111-1/+4
| | | | | | | function, be sure to adjust the resulting argument type to a pointer (if necessary). Fixes PR5910 and PR5949. llvm-svn: 93178
* Implement name lookup for conversion function template specializationsDouglas Gregor2010-01-111-10/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | (C++ [temp.mem]p5-6), which involves template argument deduction based on the type named, e.g., given struct X { template<typename T> operator T*(); } x; when we call x.operator int*(); we perform template argument deduction to determine that T=int. This template argument deduction is needed for template specialization and explicit instantiation, e.g., template<> X::operator float*() { /* ... */ } and when calling or otherwise naming a conversion function (as in the first example). This fixes PR5742 and PR5762, although there's some remaining ugliness that's causing out-of-line definitions of conversion function templates to fail. I'll look into that separately. llvm-svn: 93162
* Make sure to use ASTContext::getAs*ArrayType() when decomposing arrayDouglas Gregor2010-01-041-2/+2
| | | | | | types. Fixes APFloat.cpp compilation failure. llvm-svn: 92523
* More fixes to the handling of CVR-comparisons on array types. Adds a method toChandler Carruth2009-12-301-3/+5
| | | | | | | | | | | | QualType to get CVR-qualifiers through array types, and switches the primary comparison methods to use it. This may allow simplifying some of the callers of getUnqualifiedArrayType. Also fix the normalizing of CV-qualification during template deduction to normalize through arrays and allow a more qualified deduced array type. This fixes PR5911. llvm-svn: 92289
* Correctly refer to element CVR qualifications when determining if a type isChandler Carruth2009-12-291-53/+1
| | | | | | | | | | more or less cv-qualified than another during implicit conversion and overload resolution ([basic.type.qualifier] p5). Factors the logic out of template deduction and into the ASTContext so it can be shared. This fixes several aspects of PR5542, but not all of them. llvm-svn: 92248
* Get rid of FixedWidthIntType, as suggested by Chris and Eli.Anders Carlsson2009-12-291-1/+0
| | | | llvm-svn: 92246
* When a template-id refers to a single function template, and theDouglas Gregor2009-12-211-22/+69
| | | | | | | | | | explicitly-specified template arguments are enough to determine the instantiation, and either template argument deduction fails or is not performed in that context, we can resolve the template-id down to a function template specialization (so sayeth C++0x [temp.arg.explicit]p3). Fixes PR5811. llvm-svn: 91852
* Introduce an assertion to ensure that template argument deduction doesDouglas Gregor2009-12-211-1/+1
| | | | | | | | | not deduce an "overload" type. Such a deduction indicates a failure in semantic analysis (e.g., PR5811) that currently isn't caught until code-generation time. This assertions makes it clearer that this particular issue is a semantic-analysis problem, not a code-gen problem. llvm-svn: 91844
* Fix "using typename" and the instantiation of non-dependent using declarations.John McCall2009-12-041-0/+1
| | | | llvm-svn: 90614
* Remove remaining VISIBILITY_HIDDEN from anonymous namespaces.Benjamin Kramer2009-11-281-1/+0
| | | | llvm-svn: 90044
* Implement support for default template arguments of function templates.Douglas Gregor2009-11-251-15/+41
| | | | llvm-svn: 89874
* Encapsulate "an array of TemplateArgumentLocs and two angle bracket ↵John McCall2009-11-231-32/+19
| | | | | | | | | | locations" into a new class. Use it pervasively throughout Sema. My fingers hurt. llvm-svn: 89638
* First part of changes to eliminate problems with cv-qualifiers andDouglas Gregor2009-11-161-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | sugared types. The basic problem is that our qualifier accessors (getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at the current QualType and not at any qualifiers that come from sugared types, meaning that we won't see these qualifiers through, e.g., typedefs: typedef const int CInt; typedef CInt Self; Self.isConstQualified() currently returns false! Various bugs (e.g., PR5383) have cropped up all over the front end due to such problems. I'm addressing this problem by splitting each qualifier accessor into two versions: - the "local" version only returns qualifiers on this particular QualType instance - the "normal" version that will eventually combine qualifiers from this QualType instance with the qualifiers on the canonical type to produce the full set of qualifiers. This commit adds the local versions and switches a few callers from the "normal" version (e.g., isConstQualified) over to the "local" version (e.g., isLocalConstQualified) when that is the right thing to do, e.g., because we're printing or serializing the qualifiers. Also, switch a bunch of Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType() expressions over to Context.hasSameUnqualifiedType(T1, T2) llvm-svn: 88969
* Revert r88718, which does NOT solve the ↵Douglas Gregor2009-11-131-1/+1
| | | | | | constructor-template-as-copy-constructor issue. Big thanks to John for finding this llvm-svn: 88724
* Template argument deduction of a non-type template parameter from aDouglas Gregor2009-11-131-2/+41
| | | | | | template argument. llvm-svn: 88722
* A constructor template cannot be instantiated to a copyDouglas Gregor2009-11-131-1/+1
| | | | | | constructor. Make sure that such declarations can never be formed. llvm-svn: 88718
* Template argument deduction for template template parameters. ThisDouglas Gregor2009-11-111-43/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | permits, among other things, ripping apart and reconstructing templates via partial specialization: template<typename T> struct DeepRemoveConst { typedef T type; }; template<typename T> struct DeepRemoveConst<const T> { typedef typename DeepRemoveConst<T>::type type; }; template<template<typename> class TT, typename T> struct DeepRemoveConst<TT<T> > { typedef TT<typename DeepRemoveConst<T>::type> type; }; Also, fix a longstanding thinko in the code handling partial ordering of class template partial specializations. We were performing the second deduction without clearing out the results of the first deduction. It's amazing we got through so much code with such a horrendous error :( llvm-svn: 86893
* Introduce a new representation for template templateDouglas Gregor2009-11-111-25/+44
| | | | | | | | | | | | | | | | | | | | | | | | | parameters. Rather than storing them as either declarations (for the non-dependent case) or expressions (for the dependent case), we now (always) store them as TemplateNames. The primary change here is to add a new kind of TemplateArgument, which stores a TemplateName. However, making that change ripples to every switch on a TemplateArgument's kind, also affecting TemplateArgumentLocInfo/TemplateArgumentLoc, default template arguments for template template parameters, type-checking of template template arguments, etc. This change is light on testing. It should fix several pre-existing problems with template template parameters, such as: - the inability to use dependent template names as template template arguments - template template parameter default arguments cannot be instantiation However, there are enough pieces missing that more implementation is required before we can adequately test template template parameters. llvm-svn: 86777
* Track source information for template arguments and template specializationJohn McCall2009-10-291-20/+43
| | | | | | | types. Preserve it through template instantiation. Preserve it through PCH, although TSTs themselves aren't serializable, so that's pretty much meaningless. llvm-svn: 85500
* Implement support for semantic checking and template instantiation ofDouglas Gregor2009-10-291-32/+58
| | | | | | | | class template partial specializations of member templates. Also, fixes a silly little bug in the marking of "used" template parameters in member templates. Fixes PR5236. llvm-svn: 85447
* Audit the code for places where it is assumed that every base specifier ↵Sebastian Redl2009-10-251-1/+1
| | | | | | refers to a RecordType. Add assertions or conditions as appropriate. This fixes another crash in the Apache stdlib vector. llvm-svn: 85055
* Store the builtin types as CanQualTypes. Expand a bit on the CanQual API,John McCall2009-10-231-3/+3
| | | | | | | but also remove some methods that cause ambiguities, and generally make CanQual<blah> more analogous to QualType. llvm-svn: 84976
* Canonicality is a property of qualified types, not unqualified types.John McCall2009-10-221-2/+2
| | | | llvm-svn: 84891
* Improve template argument deduction in the case where the parameterDouglas Gregor2009-09-301-7/+1
| | | | | | | | | type is a template-id (e.g., basic_ostream<CharT, Traits>) and the argument type is a class that has a derived class matching the parameter type. Previously, we were giving up on template argument deduction too early. llvm-svn: 83177
* WIP implementation of explicit instantiation of function templates,Douglas Gregor2009-09-251-0/+118
| | | | | | | | member functions of class template specializations, and static data members. The mechanics are (mostly) present, but the semantic analysis is very weak. llvm-svn: 82789
* WIP implementation of explicit function template specialization. ThisDouglas Gregor2009-09-241-1/+1
| | | | | | | | | | | | | | | | | | | | | first implementation recognizes when a function declaration is an explicit function template specialization (based on the presence of a template<> header), performs template argument deduction + ambiguity resolution to determine which template is being specialized, and hooks There are many caveats here: - We completely and totally drop any explicitly-specified template arguments on the floor - We don't diagnose any of the extra semantic things that we should diagnose. - I haven't looked to see that we're getting the right linkage for explicit specializations On a happy note, this silences a bunch of errors that show up in libstdc++'s <iostream>, although Clang still can't get through the entire header. llvm-svn: 82728
* Refactor the representation of qualifiers to bring ExtQualType out of theJohn McCall2009-09-241-24/+19
| | | | | | | | Type hierarchy. Demote 'volatile' to extended-qualifier status. Audit our use of qualifiers and fix a few places that weren't dealing with qualifiers quite right; many more remain. llvm-svn: 82705
* Change all the Type::getAsFoo() methods to specializations of Type::getAs().John McCall2009-09-211-5/+5
| | | | | | | | | | | Several of the existing methods were identical to their respective specializations, and so have been removed entirely. Several more 'leaf' optimizations were introduced. The getAsFoo() methods which imposed extra conditions, like getAsObjCInterfacePointerType(), have been left in place. llvm-svn: 82501
* Make the construction of the code-completion string for a functionDouglas Gregor2009-09-181-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | template smarter, by taking into account which function template parameters are deducible from the call arguments. For example, template<typename RandomAccessIterator> void sort(RandomAccessIterator first, RandomAccessIterator last); will have a code-completion string like sort({RandomAccessIterator first}, {RandomAccessIterator last}) since the template argument for its template parameter is deducible. On the other hand, template<class X, class Y> X* dyn_cast(Y *Val); will have a code-completion string like dyn_cast<{class X}>({Y *Val}) since the template type parameter X is not deducible from the function call. llvm-svn: 82306
* Add an assertion and a test case, in a fruitless attempt to track down an ↵Douglas Gregor2009-09-151-0/+3
| | | | | | existing bug llvm-svn: 81885
* Slightly improved template argument deduction for use in partialDouglas Gregor2009-09-151-1/+12
| | | | | | | ordering, along with another test case for partial ordering of partial specializations. llvm-svn: 81869
* Implement partial ordering of class template partial specializations Douglas Gregor2009-09-151-6/+70
| | | | | | (C++ [temp.class.order]). llvm-svn: 81866
* Refactor MarkDeductedTemplateParameters intoDouglas Gregor2009-09-141-67/+136
| | | | | | | | MarkUsedTemplateParameters, which is able to mark template parameters used within non-deduced contexts as well as deduced contexts. Use this to finish the implementation of [temp.deduct.partial]p11. llvm-svn: 81794
* Tighten up checking of non-dependent arguments as part of templateDouglas Gregor2009-09-141-3/+13
| | | | | | | | | argument deduction. This fixes the new test case (since partial ordering does not have a "verify the results of deduction" step), and will allow failed template argument deductions to return more quickly for, e.g., matching class template partial specializations. llvm-svn: 81779
OpenPOWER on IntegriCloud