summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplateInstantiate.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* PR12057: Allow variadic template pack expansions to cross lambda boundaries.Richard Smith2012-07-251-0/+13
| | | | | | | | | | Rather than adding a ContainsUnexpandedParameterPack bit to essentially every AST node, we tunnel the bit directly up to the surrounding lambda expression when we reach a context where an unexpanded pack can not normally appear. Thus any statement or declaration within a lambda can now potentially contain an unexpanded parameter pack. llvm-svn: 160705
* PR13365: Fix code which was trying to treat an array of DeducedTemplateArgumentRichard Smith2012-07-161-56/+46
| | | | | | | | 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
* Stop instantiating a class if we hit a static_assert failure. Also, if theRichard Smith2012-07-111-1/+8
| | | | | | | static_assert fails when parsing the template, don't diagnose it again on every instantiation. llvm-svn: 160088
* PR13136:Richard Smith2012-07-091-2/+10
| | | | | | | | | | | | | | | * 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
* PR9793: Treat substitution as an instantiation step for the purpose of theRichard Smith2012-07-081-49/+42
| | | | | | | | -ftemplate-depth limit. There are various ways to get an infinite (or merely huge) stack of substitutions with no intervening instantiations. This is also consistent with gcc's behavior. llvm-svn: 159907
* Be more eager about setting the 'Invalid' bit on an invalid classDouglas Gregor2012-07-021-13/+10
| | | | | | | | | template instantiation. I wasn't able to reproduce this down to anything small enough to put in our test suite, but it's "obviously" okay to set the invalid bit earlier and precludes a known-broken-but-not-marked-broken class from being used elsewhere. llvm-svn: 159584
* Give L__FUNCTION__ the right type in templates. PR13206.Nico Weber2012-06-251-1/+5
| | | | llvm-svn: 159171
* Still more Doxygen documentation fixes:James Dennett2012-06-141-1/+1
| | | | | | | | * 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
* PR13064: Store whether an in-class initializer uses direct or copyRichard Smith2012-06-101-3/+1
| | | | | | | initialization, and use that information to produce the right kind of initialization during template instantiation. llvm-svn: 158288
* CXXThisScopeRAII objects aren't free, don't compute one if it's unused.Benjamin Kramer2012-05-171-1/+1
| | | | llvm-svn: 156987
* PR12710 - broken default argument handling for templates.David Blaikie2012-05-011-7/+5
| | | | | | | | | | | | | | | I broke this in r155838 by not actually instantiating non-dependent default arg expressions. The motivation for that change was to avoid producing duplicate conversion warnings for such default args (we produce them once when we parse the template - there's no need to produce them at each instantiation) but without actually instantiating the default arg, things break in weird ways. Technically, I think we could still get the right diagnostic experience without the bugs if we instantiated the non-dependent args (for non-dependent params only) immediately, rather than lazily. But I'm not sure if such a refactoring/ change would be desirable so here's the conservative fix for now. llvm-svn: 155893
* Fix PR12378: provide conversion warnings on default args of function templatesDavid Blaikie2012-04-301-2/+7
| | | | | | | | | | | | | Apparently we weren't checking default arguments when they were instantiated. This adds the check, fixes the lack of instantiation caching (which seems like it was mostly implemented but just missed the last step), and avoids implementing non-dependent default args (for non-dependent parameter types) as uninstantiated default arguments (so that we don't warn once for every instantiation when it's not instantiation dependent). Reviewed by Richard Smith. llvm-svn: 155838
* PR12647: An alias template instantiation which occurs in a SFINAE context isRichard Smith2012-04-261-1/+6
| | | | | | itself a SFINAE context. llvm-svn: 155621
* Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.Richard Smith2012-04-171-0/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We have a new flavor of exception specification, EST_Uninstantiated. A function type with this exception specification carries a pointer to a FunctionDecl, and the exception specification for that FunctionDecl is instantiated (if needed) and used in the place of the function type's exception specification. When a function template declaration with a non-trivial exception specification is instantiated, the specialization's exception specification is set to this new 'uninstantiated' kind rather than being instantiated immediately. Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs on-demand. Also, any odr-use of a function triggers the instantiation of its exception specification (the exception specification could be needed by IRGen). In passing, fix two places where a DeclRefExpr was created but the corresponding function was not actually marked odr-used. We used to get away with this, but don't any more. Also fix a bug where instantiating an exception specification which refers to function parameters resulted in a crash. We still have the same bug in default arguments, which I'll be looking into next. This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to parse (and, in very limited testing, support) all of libstdc++4.7's standard headers. llvm-svn: 154886
* Implement C++11 [expr.prim.general]p3, which permits the use of 'this'Douglas Gregor2012-04-161-18/+51
| | | | | | | | | | | | | | | | | | | | | | | in the declaration of a non-static member function after the (optional) cv-qualifier-seq, which in practice means in the exception specification and late-specified return type. The new scheme here used to manage 'this' outside of a member function scope is more general than the Scope-based mechanism previously used for non-static data member initializers and late-parsesd attributes, because it can also handle the cv-qualifiers on the member function. Note, however, that a separate pass is required for static member functions to determine whether 'this' was used, because we might not know that we have a static function until after declaration matching. Finally, this introduces name mangling for 'this' and for the implicit 'this', which is intended to match GCC's mangling. Independent verification for the new mangling test case would be appreciated. Fixes PR10036 and PR12450. llvm-svn: 154799
* Implement support for null non-type template arguments for non-typeDouglas Gregor2012-04-061-9/+15
| | | | | | | template parameters of pointer, pointer-to-member, or nullptr_t type in C++11. Fixes PR9700 / <rdar://problem/11193097>. llvm-svn: 154219
* When defining a forward-declared enum, don't try to attach the definition toRichard Smith2012-03-231-1/+2
| | | | | | | a previous declaration if the redeclaration is invalid. That way lies madness. Fixes a crash-on-invalid reported by Abramo. llvm-svn: 153349
* Support for definitions of member enumerations of class templates outside theRichard Smith2012-03-231-1/+14
| | | | | | | class template's definition, and for explicit specializations of such enum members. llvm-svn: 153304
* Instantiating a class template should not instantiate the definition of anyRichard Smith2012-03-141-31/+140
| | | | | | | | scoped enumeration members. Later uses of an enumeration temploid as a nested name specifier should cause its instantiation. Plus some groundwork for explicit specialization of member enumerations of class templates. llvm-svn: 152750
* Unify naming of LangOptions variable/get function across the Clang stack ↵David Blaikie2012-03-111-3/+3
| | | | | | | | | | (Lex to AST). The member variable is always "LangOpts" and the member function is always "getLangOpts". Reviewed by Chris Lattner llvm-svn: 152536
* Introduce support for template instantiation of lambdaDouglas Gregor2012-02-131-0/+8
| | | | | | | | | | | | | | | | | | expressions. This is mostly a simple refact, splitting the main "start a lambda expression" function into smaller chunks that are driven either from the parser (Sema::ActOnLambdaExpr) or during AST transformation (TreeTransform::TransformLambdaExpr). A few minor interesting points: - Added new entry points for TreeTransform, so that we can explicitly establish the link between the lambda closure type in the template and the lambda closure type in the instantiation. - Added a bit into LambdaExpr specifying whether it had an explicit result type or not. We should have had this anyway. This code is 'lightly' tested. llvm-svn: 150417
* Represent C++ direct initializers as ParenListExprs before semantic analysisSebastian Redl2012-02-111-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | instead of having a special-purpose function. - ActOnCXXDirectInitializer, which was mostly duplication of AddInitializerToDecl (leading e.g. to PR10620, which Eli fixed a few days ago), is dropped completely. - MultiInitializer, which was an ugly hack I added, is dropped again. - We now have the infrastructure in place to distinguish between int x = {1}; int x({1}); int x{1}; -- VarDecl now has getInitStyle(), which indicates which of the above was used. -- CXXConstructExpr now has a flag to indicate that it represents list- initialization, although this is not yet used. - InstantiateInitializer was renamed to SubstInitializer and simplified. - ActOnParenOrParenListExpr has been replaced by ActOnParenListExpr, which always produces a ParenListExpr. Placed that so far failed to convert that back to a ParenExpr containing comma operators have been fixed. I'm pretty sure I could have made a crashing test case before this. The end result is a (I hope) considerably cleaner design of initializers. More importantly, the fact that I can now distinguish between the various initialization kinds means that I can get the tricky generalized initializer test cases Johannes Schaub supplied to work. (This is not yet done.) This commit passed self-host, with the resulting compiler passing the tests. I hope it doesn't break more complicated code. It's a pretty big change, but one that I feel is necessary. llvm-svn: 150318
* For class template implicit instantiation, also update its location to pointArgyrios Kyrtzidis2012-02-111-0/+1
| | | | | | | | | | | | | | | | | | to the pattern template that it came from, otherwise we had this situation: template <typename T1, typename T2> struct S { }; template <typename T> struct S<T, int> { }; void f() { S<int, int> s; // location of declaration "S<int, int>" was of "S<T1, T2>" not "S<T, int>" } llvm-svn: 150290
* Move instantiateTemplateAttribute into the sema namespace, make helpers static.Benjamin Kramer2012-02-061-2/+6
| | | | llvm-svn: 149864
* When we're substituting into a function parameter pack and expect toDouglas Gregor2012-01-251-8/+18
| | | | | | | get a function parameter pack (but don't due to weird substitutions), complain. Fixes the last bit of PR11848. llvm-svn: 148960
* Fix PR11848: decree that an alias template contains an unexpanded parameter packRichard Smith2012-01-251-1/+1
| | | | | | | | | | | | | iff its substitution contains an unexpanded parameter pack. This has the effect that we now reject declarations such as this (which we used to crash when expanding): template<typename T> using Int = int; template<typename ...Ts> void f(Int<Ts> ...ints); The standard is inconsistent on how this case should be treated. llvm-svn: 148905
* Delayed template instantiation of late-parsed attributes.DeLesley Hutchins2012-01-201-0/+23
| | | | llvm-svn: 148595
* Remove unreachable code in Clang. (replace with llvm_unreachable where ↵David Blaikie2012-01-171-2/+2
| | | | | | appropriate or when GCC requires it) llvm-svn: 148292
* De-virtualize getPreviousDecl() and getMostRecentDecl() when we knowDouglas Gregor2012-01-141-2/+2
| | | | | | | | | | | | we have a redeclarable type, and only use the new virtual versions (getPreviousDeclImpl() and getMostRecentDeclImpl()) when we don't have that type information. This keeps us from penalizing users with strict type information (and is the moral equivalent of a "final" method). Plus, settle on the names getPreviousDecl() and getMostRecentDecl() throughout. llvm-svn: 148187
* Fix a crash on invalid, http://llvm.org/pr11599Nico Weber2011-12-201-2/+10
| | | | llvm-svn: 146988
* Fixed implicit instantiations source range.Abramo Bagnara2011-11-181-1/+3
| | | | llvm-svn: 144977
* Fixed source range for template implicit instantiations.Abramo Bagnara2011-10-031-0/+3
| | | | llvm-svn: 141018
* Only print _Bool as 'bool' when 'bool' is defined as an object-likeDouglas Gregor2011-09-271-2/+2
| | | | | | macro whose only replacement token is '_Bool'. llvm-svn: 140656
* When 'bool' is not a built-in type but is defined as a macro, printDouglas Gregor2011-09-271-2/+2
| | | | | | | 'bool' rather than '_Bool' within types, to make things a bit more readable. Fixes <rdar://problem/10063263>. llvm-svn: 140650
* ArrayRef-ifying the fields passed to Sema::ActOnFieldsDavid Blaikie2011-09-221-3/+2
| | | | llvm-svn: 140293
* ArrayRef-ifying the UnexpandedParameterPacks passed to ↵David Blaikie2011-09-221-4/+2
| | | | | | Sema::CheckParameterPacksForExpansion llvm-svn: 140290
* Implement function template specialization at class scope extension in ↵Francois Pichet2011-08-141-2/+3
| | | | | | | | | | | | | | | | | Microsoft mode. A new AST node is introduced: ClassScopeFunctionSpecialization. This node holds a FunctionDecl that is not yet specialized; then during the class template instantiation the ClassScopeFunctionSpecialization will spawn the actual function specialization. Example: template <class T> class A { public: template <class U> void f(U p) { } template <> void f(int p) { } // <== class scope specialization }; This extension is necessary to parse MSVC standard C++ headers, MFC and ATL code. BTW, with this feature in, clang can parse (-fsyntax-only) all the MSVC 2010 standard header files without any error. llvm-svn: 137573
* remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner2011-07-231-16/+15
| | | | | | | | LLVM.h imports them into the clang namespace. llvm-svn: 135852
* Replace r134583's fix for PR10290 with one which also works for ↵Richard Smith2011-07-201-26/+8
| | | | | | non-value-dependent cases. llvm-svn: 135543
* Create a new expression node, SubstNonTypeTemplateParmExpr,John McCall2011-07-151-56/+53
| | | | | | | | to represent a fully-substituted non-type template parameter. This should improve source fidelity, as well as being generically useful for diagnostics and such. llvm-svn: 135243
* In an in-class initialization, defer checks for value-dependent initializationNick Lewycky2011-07-071-3/+5
| | | | | | expressions. llvm-svn: 134583
* Introduce the notion of instantiation dependence into Clang's AST. ADouglas Gregor2011-07-011-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | type/expression/template argument/etc. is instantiation-dependent if it somehow involves a template parameter, even if it doesn't meet the requirements for the more common kinds of dependence (dependent type, type-dependent expression, value-dependent expression). When we see an instantiation-dependent type, we know we always need to perform substitution into that instantiation-dependent type. This keeps us from short-circuiting evaluation in places where we shouldn't, and lets us properly implement C++0x [temp.type]p2. In theory, this would also allow us to properly mangle instantiation-dependent-but-not-dependent decltype types per the Itanium C++ ABI, but we aren't quite there because we still mangle based on the canonical type in cases like, e.g., template<unsigned> struct A { }; template<typename T> void f(A<sizeof(sizeof(decltype(T() + T())))>) { } template void f<int>(A<sizeof(sizeof(int))>); and therefore get the wrong answer. llvm-svn: 134225
* Preserve that a TemplateName was arrived at by substitutingJohn McCall2011-06-301-2/+3
| | | | | | | | | | | for a template template parameter. Uses to follow. I've also made the uniquing of SubstTemplateTemplateParmPacks use a ContextualFoldingSet as a minor space efficiency. llvm-svn: 134137
* When performing substitution of default template template parametersDouglas Gregor2011-06-151-2/+14
| | | | | | | | | | before the template parameters have acquired a proper context (e.g., because the enclosing context has yet to be built), provide empty parameter lists for all outer template parameter scopes to inhibit any substitution for those template parameters. Fixes PR9643 / <rdar://problem/9251019>. llvm-svn: 133055
* Implement support for C++11 in-class initialization of non-static data members.Richard Smith2011-06-111-2/+46
| | | | llvm-svn: 132878
* Made changes to how 'struct'/'class' mismatches are handled in ↵Richard Trieu2011-06-101-1/+2
| | | | | | | | | | | | | | | | | -Wmismatched-tags. - Removed fix-it hints from template instaniations since changes to the templates are rarely helpful. - Changed the caret in template instaniations from the class/struct name to the class/struct keyword, matching the other warnings. - Do not offer fix-it hints when multiple declarations disagree. Warnings are still given. - Once a definition is found, offer a fix-it hint to all previous declarations with wrong tag. - Declarations that disagree with a previous definition will get a fix-it hint to change the declaration. llvm-svn: 132831
* Add an assertion to tell us when we're going off the deep end tryingDouglas Gregor2011-05-221-2/+6
| | | | | | | | to determine outer template arguments lists for template parameters. This is actually the problem behind PR9643, which I have yet to figure out how to fix. llvm-svn: 131822
* When determining whether we need to instantiate a function type,Douglas Gregor2011-05-091-0/+6
| | | | | | | also consider whether any of the parameter types (as written, prior to decay) are dependent. Fixes PR9880 and <rdar://problem/9408413>. llvm-svn: 131099
* Modify some deleted function methods to better reflect reality:Alexis Hunt2011-05-061-2/+2
| | | | | | | | | | | | | | | | | | | | - New isDefined() function checks for deletedness - isThisDeclarationADefinition checks for deletedness - New doesThisDeclarationHaveABody() does what isThisDeclarationADefinition() used to do - The IsDeleted bit is not propagated across redeclarations - isDeleted() now checks the canoncial declaration - New isDeletedAsWritten() does what it says on the tin. - isUserProvided() now correct (thanks Richard!) This fixes the bug that we weren't catching void foo() = delete; void foo() {} as being a redefinition. llvm-svn: 131013
* Implement support for C++0x alias templates.Richard Smith2011-05-051-4/+8
| | | | llvm-svn: 130953
OpenPOWER on IntegriCloud