Commit Graph

204 Commits

Author SHA1 Message Date
Douglas Gregor a5d5c749b1 Move a bunch of tests into temp.param, and write a few tests for paragraphs that hadn't been touched before
llvm-svn: 73288
2009-06-13 06:59:07 +00:00
Eli Friedman 9a0e23c495 Fix for PR4382: allow instantiating dependent nested name specifiers.
I'm not completely sure this is the right way to fix this issue, but it seems 
reasonable, and it's consistent with the non-template code for this 
construct.

llvm-svn: 73285
2009-06-13 04:51:30 +00:00
Anders Carlsson 20ee0ed4ea If a CXXRecordDecl is a class template, the 'this' type should be the injected class name type. Fixes pr4383.
llvm-svn: 73284
2009-06-13 02:59:33 +00:00
Anders Carlsson 15201f19ba More work on type parameter packs.
llvm-svn: 73281
2009-06-13 02:08:00 +00:00
Douglas Gregor 91772d1d76 When some template parameters of a class template partial
specialization cannot be deduced, produce a warning noting that the
affected class template partial specialization will never be used.

llvm-svn: 73274
2009-06-13 00:26:55 +00:00
Anders Carlsson 327865db53 A parameter pack must always come last in a class template.
llvm-svn: 73269
2009-06-12 23:20:15 +00:00
Anders Carlsson f986ba7528 Address more comments from Doug.
llvm-svn: 73267
2009-06-12 23:09:56 +00:00
Anders Carlsson d382435014 Parameter packs can't have default arguments.
llvm-svn: 73262
2009-06-12 22:30:13 +00:00
Douglas Gregor 30b0197169 Finish implementing checking of class template partial specializations
llvm-svn: 73260
2009-06-12 22:21:45 +00:00
Douglas Gregor 09a3023e65 Diagnose C++ [temp.class.spec]p9b3, where a class template partial
specialization's arguments are identical to the implicit template
arguments of the primary template. Typically, this is meant to be a
declaration/definition of the primary template, so we give that
advice.

llvm-svn: 73259
2009-06-12 22:08:06 +00:00
Douglas Gregor 8cfd2ba76d Diagnose the incorrect use of non-type template arguments for class
template partial specializations.

llvm-svn: 73254
2009-06-12 21:21:02 +00:00
Anders Carlsson 01e9e93485 Parse support for C++0x type parameter packs.
llvm-svn: 73247
2009-06-12 19:58:00 +00:00
Douglas Gregor d52220513f Verify that the template parameters of a class template partial
specialization do not have default arguments 
(C++ [temp.class.spec]p10). 

llvm-svn: 73245
2009-06-12 19:43:02 +00:00
Anders Carlsson b0e8e228ff Fix PR4365.
llvm-svn: 73240
2009-06-12 18:53:02 +00:00
Anders Carlsson a767eeed19 Deducation and instantiation of block types.
llvm-svn: 73232
2009-06-12 16:23:10 +00:00
Douglas Gregor 74eba0b679 Once we have deduced the template arguments of a class template
partial specialization, substitute those template arguments back into
the template arguments of the class template partial specialization to
see if the results still match the original template arguments.

This code is more general than it needs to be, since we don't yet
diagnose C++ [temp.class.spec]p9. However, it's likely to be needed
for function templates.

llvm-svn: 73196
2009-06-11 18:10:32 +00:00
Anders Carlsson 40ed344c92 Add a null check that fixes the crash in PR4362, and make sure to instantiate non-type template arguments.
llvm-svn: 73193
2009-06-11 16:06:49 +00:00
Eli Friedman dd49ee3fb4 Make sure to calculate value-dependence correctly when deal with ICEs.
(Actually, this isn't precisely correct, but it doesn't make 
sense to query whether an expression that isn't an ICE is 
value-dependent anyway.)

llvm-svn: 73179
2009-06-11 01:11:20 +00:00
Eli Friedman 88681cce60 Move test to be with the other typename tests.
llvm-svn: 73178
2009-06-11 01:01:02 +00:00
Douglas Gregor 637d9984f0 Template argument deduction for member pointers.
Also, introduced some of the framework for performing instantiation as
part of template argument deduction.

llvm-svn: 73175
2009-06-10 23:47:09 +00:00
Douglas Gregor 0bdc1f5eef Handle member pointer types with dependent class types (e.g., int
T::*) and implement template instantiation for member pointer types.

llvm-svn: 73151
2009-06-09 22:17:39 +00:00
Douglas Gregor ed74eb81e1 Example metaprogram for reversing and searching in a type list
llvm-svn: 73147
2009-06-09 21:22:32 +00:00
Douglas Gregor 4fbe3e3014 Implement template argument deduction for class template
specialization types. As the example shows, we can now compute the
length of a type-list using a template metaprogram and class template
partial specialization.

llvm-svn: 73136
2009-06-09 16:35:58 +00:00
Anders Carlsson 096e6eeb68 Address comments from Doug.
llvm-svn: 73077
2009-06-08 19:22:23 +00:00
Douglas Gregor 6f998fcb1d Test template argument deduction on function types a little more
llvm-svn: 73072
2009-06-08 16:04:08 +00:00
Anders Carlsson 2128ec7cdd Template argument deduction for function types.
llvm-svn: 73070
2009-06-08 15:19:08 +00:00
Anders Carlsson 0880e9f58d Instantiation support for more Obj-C expressions, string literals, @selector and @protocol expressions.
llvm-svn: 73036
2009-06-07 19:51:47 +00:00
Anders Carlsson 315d2294f8 Template instantiation support for Obj-C @encode expressions.
llvm-svn: 73034
2009-06-07 18:45:35 +00:00
Anders Carlsson 03c9e87410 Fix another crash and actually make the test case work.
llvm-svn: 72913
2009-06-05 02:45:24 +00:00
Anders Carlsson dd096d888b Fix a case when the TemplateArgs vector can be empty.
llvm-svn: 72911
2009-06-05 02:12:32 +00:00
Douglas Gregor b7ae10f764 Several improvements to template argument deduction:
- Once we have deduced template arguments for a class template partial
    specialization, we use exactly those template arguments for instantiating
    the definition of the class template partial specialization.
  - Added template argument deduction for non-type template parameters.
  - Added template argument deduction for dependently-sized array types.

With these changes, we can now implement, e.g., the remove_reference
type trait. Also, Daniel's Ackermann template metaprogram now compiles
properly.

llvm-svn: 72909
2009-06-05 00:53:49 +00:00
Anders Carlsson 35533d11b3 Template argument deduction for incomplete and constant array types. Doug, please review.
llvm-svn: 72844
2009-06-04 04:11:30 +00:00
Douglas Gregor 5cdac0a52e Template argument deduction for references
llvm-svn: 72822
2009-06-04 00:21:18 +00:00
Douglas Gregor 55ca8f6443 When performing template argument deduction, ensure that multiple
deductions of the same template parameter are equivalent. This allows
us to implement the is_same type trait (!).

Also, move template argument deduction into its own file and update a
few build systems with this change (grrrr).

llvm-svn: 72819
2009-06-04 00:03:07 +00:00
Argyrios Kyrtzidis b1d51aa18a Use "()" instead of "(void)" when pretty-printing a parameter-less function type for C++.
llvm-svn: 72747
2009-06-03 02:06:50 +00:00
Anders Carlsson 6f6f6005ab After spending 15 minutes trying to figure out why this was crashing, I realized it was a bug in the test case :)
llvm-svn: 72680
2009-06-01 00:40:08 +00:00
Douglas Gregor 2373c599b5 Initial infrastructure for class template partial specialization. Here
we have the basics of declaring and storing class template partial
specializations, matching class template partial specializations at
instantiation time via (limited) template argument deduction, and
using the class template partial specialization's pattern for
instantiation. 

This patch is enough to make a simple is_pointer type trait work, but
not much else.

llvm-svn: 72662
2009-05-31 09:31:02 +00:00
Douglas Gregor 7de5966d76 Create a new PrintingPolicy class, which we pass down through the AST
printing logic to help customize the output. For now, we use this
rather than a special flag to suppress the "struct" when printing
"struct X" and to print the Boolean type as "bool" in C++ but "_Bool"
in C.

llvm-svn: 72590
2009-05-29 20:38:28 +00:00
Sebastian Redl eed0ec5fdb Fix usage of placement new. Placement new is not actually declared implicitly.
llvm-svn: 72576
2009-05-29 16:43:59 +00:00
Douglas Gregor 0558094464 Follow-on test case for template instantiation of interesting DeclGroups
llvm-svn: 72569
2009-05-29 14:26:40 +00:00
Douglas Gregor 8157b07caf Now that we have declared/defined tag types within DeclGroups,
instantiation of tags local to member functions of class templates
(and, eventually, function templates) works when the tag is defined as
part of the decl-specifier-seq, e.g.,

  struct S { T x, y; } s1;

Also, make sure that we don't try to default-initialize a dependent
type.

llvm-svn: 72568
2009-05-29 14:25:00 +00:00
Douglas Gregor 019d3750cb Add the missing public: thanks, Fariborz
llvm-svn: 72528
2009-05-28 16:41:44 +00:00
Douglas Gregor 9e927abc41 Introduced DeclContext::isDependentContext, which determines whether a
given DeclContext is dependent on type parameters. Use this to
properly determine whether a TagDecl is dependent; previously, we were
missing the case where the TagDecl is a local class of a member
function of a class template (phew!).

Also, make sure that, when we instantiate declarations within a member
function of a class template (or a function template, eventually),
that we add those declarations to the "instantiated locals" map so
that they can be found when instantiating declaration references.

Unfortunately, I was not able to write a useful test for this change,
although the assert() that fires when uncommenting the FIXME'd line in
test/SemaTemplate/instantiate-declref.cpp tells the "experienced user"
that we're now doing the right thing.

llvm-svn: 72526
2009-05-28 16:34:51 +00:00
Douglas Gregor e44a2adf41 Reimplement much of the way that we track nested classes in the
parser. Rather than placing all of the delayed member function
declarations and inline definitions into a single bucket corresponding
to the top-level class, we instead mirror the nesting structure of the
nested classes and place the delayed member functions into their
appropriate place. Then, when we actually parse the delayed member
function declarations, set up the scope stack the same way as it was
when we originally saw the declaration, so that we can find, e.g.,
template parameters that are in scope.

llvm-svn: 72502
2009-05-27 23:11:45 +00:00
Sebastian Redl eed3d4c73e Fix the type of a enum non-type template argument within the instantiation.
llvm-svn: 72489
2009-05-27 19:21:29 +00:00
Douglas Gregor cd3a097925 Simplify, and improve the performance of, template instantiation for
declaration references. The key realization is that dependent Decls,
which actually require instantiation, can only refer to the current
instantiation or members thereof. And, since the current context
during instantiation contains all of those members of the current
instantiation, we can simply find the real instantiate that matches up
with the "current instantiation" template.

llvm-svn: 72486
2009-05-27 17:54:46 +00:00
Douglas Gregor b8006fafe8 Add some more tests for instantiation of declaration references. Also,
improve some error recovery with explicit template instantiation.

llvm-svn: 72484
2009-05-27 17:30:49 +00:00
Douglas Gregor 7a74938fca Enumeration declarations that were instantiated from an enumeration
within a template now have a link back to the enumeration from which
they were instantiated. This means that we can now find the
instantiation of an anonymous enumeration.

llvm-svn: 72482
2009-05-27 17:20:35 +00:00
Douglas Gregor f98d9b60db Improve name lookup for and template instantiation of declaration
references. There are several smallish fixes here:

  - Make sure we look through template parameter scope when
    determining whether we're parsing a nested class (or nested class
    *template*). This makes sure that we delay parsing the bodies of
    inline member functions until after we're out of the outermost
    class (template) scope.
  - Since the bodies of member functions are always parsed
    "out-of-line", even when they were declared in-line, teach
    unqualified name lookup to look into the (semantic) parents.
  - Use the new InstantiateDeclRef to handle the instantiation of a
    reference to a declaration (in DeclRefExpr), which drastically
    simplifies template instantiation for DeclRefExprs.
  - When we're instantiating a ParmVarDecl, it must be in the current
    instantiation scope, so only look there.

Also, remove the #if 0's and FIXME's from the dynarray example, which
now compiles and executes thanks to Anders and Eli.

llvm-svn: 72481
2009-05-27 17:07:49 +00:00
Douglas Gregor 5178331379 Initial stab at a generalized operation for determining the
instantiation of a declaration from the template version (or version
that lives in a template) and a given set of template arguments. This
needs much, much more testing, but it suffices for simple examples
like

  typedef T* iterator;
  iterator begin();

llvm-svn: 72461
2009-05-27 05:35:12 +00:00