Граф коммитов

637 Коммитов

Автор SHA1 Сообщение Дата
Daniel Dunbar 78d5590d89 Use '-FOO' 'BAR' instead of '-FOO=BAR' in tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90122 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-30 08:41:04 +00:00
Daniel Dunbar a75a92dfff Remove unnecessary -fms-extensions=0 from tests (this command line syntax is going away).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90066 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-29 09:31:53 +00:00
Douglas Gregor 2afce7248b Refactor our handling of expression evaluation contexts, so that Sema
maintains a stack of evaluation contexts rather than having the parser
do it. This change made it simpler to track in which contexts
temporaries were created, so that we could...

"Forget" about temporaries created within unevaluated contexts, so
that we don't build a CXXExprWithTemporaries and, therefore, destroy
the integral-constness of our expressions. Fixes PR5609.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89908 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-26 00:44:06 +00:00
Douglas Gregor d85b5b9b8f Implement the rules in C++ [basic.link] and C99 6.2.2 for computing
the linkage of a declaration. Switch the lame (and completely wrong)
NamedDecl::hasLinkage() over to using the new NamedDecl::getLinkage(),
along with the "can this declaration be a template argument?" check
that started all of this.

Fixes -fsyntax-only for PR5597.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89891 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-25 22:24:25 +00:00
Douglas Gregor 51ffb0c9d4 Implement support for default template arguments of function templates.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89874 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-25 18:55:14 +00:00
Douglas Gregor 04895d301e "Do" loops cannot have condition variables, so don't parse them.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89801 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-24 21:34:32 +00:00
John McCall 26416068d3 Fix some major problems dealing with dependently-qualified names in implicit
member-reference contexts.  Fixes some clang-on-clang asserts.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89796 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-24 20:33:45 +00:00
Douglas Gregor ac564f3e8d Improve type-checking of templates by distinguishing between members
of the current instantiation and members of an unknown specialization
when type-checking a qualified-if expression.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89653 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-23 12:39:54 +00:00
Douglas Gregor 7edfb69ae1 Do not mark declarations as used when performing overload resolution. Fixes PR5541
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89652 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-23 12:27:39 +00:00
Douglas Gregor 3ebd753991 Tolerate extraneous "template<>" headers better, downgrading the
complaint to a warning and providing a helpful node in the case where
the "template<>" header is redundant because the corresponding
template-id refers to an explicit specialization. C++0x might still
change this behavior, and existing practice is all over the place on
the number of "template<>" headers actually needed.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89651 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-23 12:11:45 +00:00
Douglas Gregor 31658dfe90 When checking the base object of a member access expression (b.foo,
b->foo), don't look through pointers unless we have an -> operator.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89480 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-20 19:58:21 +00:00
Douglas Gregor 699ee52b2f Teach FixOverloadedFunctionReference to build new expression ASTs rather
than tweaking existing ASTs, since we were (*gasp*) stomping on ASTs
within templates. I'm glad we found this little stick of TNT early...



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89475 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-20 19:42:02 +00:00
Douglas Gregor f3c1f0e136 When we have a non-dependent expression such as
A::f

that occurs within a non-static member function with a type-dependent
"this", don't consider this to be a case for introduction of an
implicit "(*this)." to refer to a specific member function unless we
know (at template definition time) that A is a base class of *this.

There is some disagreement here between GCC, EDG, and Clang about the
handling of this case. I believe that Clang now has the correct,
literal interpretation of the standard, but have asked for
clarification (c++std-core-15483).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89425 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-20 00:59:20 +00:00
Douglas Gregor 73460a32bc Deduce a ConstantArrayType from a value-dependent initializer list
rather than punting to a DependentSizedArrayType, tightening up our
type checking for template definitions. Thanks, John!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89407 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-19 23:25:22 +00:00
Douglas Gregor cb78d8852a Cope with an amusingly little anomaly with dependent types and
incomplete array initialization, where we have the following in a
template:

  int a[] = { 1, 2, something-value-dependent };
  // ...
  sizeof(a);

The type of "a" appears to be a non-dependent IncompleteArrayType, but
treating it as such makes the sizeof(a) fail at template definition
time. We now correctly handle this by morphing the IncompleteArrayType
into a DependentSizedArrayType with a NULL expression, indicating that
its size has no corresponding expression (and, therefore, the type is
distinct from others).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89366 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-19 18:03:26 +00:00
Eli Friedman 264c1f8ec8 The sub-statement of a case statement is not an unevaluated context!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89303 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-19 03:14:00 +00:00
Fariborz Jahanian cc5306ac8a Improve on diagnosing type mismatches because of
lack of viable convesion functions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89216 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-18 18:26:29 +00:00
Daniel Dunbar 8ee15dc2e2 Use clang to run tests which include headers from the system.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89085 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-17 10:14:55 +00:00
Douglas Gregor 48c32a7e7c Implement template instantiation for using directives, which is dead simple.
Also, make the "don't know how to instantiate a particular kind of
declaration" diagnostic nicer, so we don't have to trap Clang in a
debugger to figure out what went wrong.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89050 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-17 06:07:40 +00:00
Douglas Gregor 03c5705a99 Require the object type of a member access expression ("." or "->") to
be complete.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89042 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-17 05:17:33 +00:00
Eli Friedman 1a3c75f32f Fix PR5488: special-case the overloaded arrow operator so that we don't try to
treat it as a unary operator.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88938 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-16 19:13:03 +00:00
Douglas Gregor 66724ea67d If we attempt to add a constructor template specialization that looks
like a copy constructor to the overload set, just ignore it. This
ensures that we don't try to use such a constructor as a copy
constructor *without* triggering diagnostics at the point of
declaration.

Note that we *do* diagnose such copy constructors when explicitly
written by the user (e.g., as an explicit specialization).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88733 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-14 01:20:54 +00:00
Douglas Gregor fd47648b5d Revert r88718, which does NOT solve the constructor-template-as-copy-constructor issue. Big thanks to John for finding this
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88724 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-13 23:59:09 +00:00
Douglas Gregor 15755cb839 Template argument deduction of a non-type template parameter from a
template argument.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88722 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-13 23:45:44 +00:00
Douglas Gregor cad84b7c12 A constructor template cannot be instantiated to a copy
constructor. Make sure that such declarations can never be formed.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88718 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-13 23:14:53 +00:00
Douglas Gregor caddba07f8 Recognize (and check) pointer-to-member template arguments that are
non-type template parameters or constants of pointer-to-member
type. Once checked, be sure to retain those pointer-to-member
constants as expressions if they are dependent, or as declarations if
they are not dependent.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87010 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-12 18:38:13 +00:00
Douglas Gregor 231edff790 When instantiating a reference to a non-type template parameter of pointer to
member type (e.g., T Class::*Member), build a pointer-to-member
constant expression. Previously, we we just building a simple
declaration reference expression, which meant that the expression was
not treated as a pointer to member.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87000 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-12 17:40:13 +00:00
Douglas Gregor fb898e17cf When comparing template parameter lists, distinguish between three cases:
- Comparing template parameter lists to determine if we have a redeclaration
  - Comparing template parameter lists to determine if we have equivalent
    template template parameters
  - Comparing template parameter lists to determine whether a template 
    template argument is valid for a given template template parameter.

Previously, we did not distinguish between the last two cases, which
got us into trouble when we were looking for exact type matches
between the types of non-type template parameters that were dependent
types. Now we do, so we properly delay checking of template template
arguments until instantiation time.

Also, fix an accidental fall-through in a case statement that was
causing crashes.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86992 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-12 16:20:59 +00:00
Douglas Gregor 8b13c08b1a Improve recovery in a wonky case where one tries to specialize a
template template parameter.

When building a template-id type, check whether the template-name
itself is dependent (even if the template arguments are not!) and
handle it as a template-id type.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86913 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-12 00:46:20 +00:00
Douglas Gregor eaf75f4e0f Remove an overly-eager assertion when replacing tokens with an
annotation token, because some of the tokens we're annotating might
not be in the set of cached tokens (we could have consumed them
unconditionally).

Also, move the tentative parsing from ParseTemplateTemplateArgument
into the one caller that needs it, improving recovery.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86904 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-12 00:03:40 +00:00
Douglas Gregor db0d4b751e Template argument deduction for template template parameters. This
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 :(



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86893 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-11 23:06:43 +00:00
Douglas Gregor f35f828f98 Improve diagnostics when a default template argument does not match
with its corresponding template parameter. This can happen when we
performed some substitution into the default template argument and
what we had doesn't match any more, e.g.,

  template<int> struct A;
  template<typename T, template<T> class X = A> class B;

  B<long> b;

Previously, we'd emit a pretty but disembodied diagnostic showing how
the default argument didn't match the template parameter. The
diagnostic was good, but nothing tied it to the *use* of the default
argument in "B<long>". This commit fixes that.

Also, tweak the counting of active template instantiations to avoid
counting non-instantiation records, such as those we create for
(surprise!) checking default arguments, instantiating default
arguments, and performing substitutions as part of template argument
deduction.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86884 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-11 21:54:23 +00:00
Douglas Gregor 9148c3f582 Before checking a template template argument against its corresponding
template template parameter, substitute any prior template arguments
into the template template parameter. This, for example, allows us to
properly check the template template argument for a class such as:

  template<typename T, template<T Value> class X> struct Foo;

The actual implementation of this feature was trivial; most of the
change is dedicated to giving decent diagnostics when this
substitution goes horribly wrong. We now get a note like:

  note: while substituting prior template arguments into template
      template parameter 'X' [with T = float]

As part of this change, enabled some very pedantic checking when
comparing template template parameter lists, which shook out a bug in
our overly-eager checking of default arguments of template template
parameters. We now perform only minimal checking of such default
arguments when they are initially parsed.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86864 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-11 19:13:48 +00:00
Douglas Gregor 9106ef78f8 Instantiation of template template parameters for nested templates, e.g.,
template<typename T>
  struct X {
    template<template<T Value> class Y> struct Inner;
  };



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86844 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-11 16:58:32 +00:00
Douglas Gregor 7bb87fca7d Fix speculative parsing of dependent template names in
nested-name-specifiers so that they don't gobble the template name (or
operator-function-id) unless there is also a
template-argument-list. For example, given

  T::template apply

we would previously consume both "template" and "apply" as part of
parsing the nested-name-specifier, then error when we see that there
is no "<" starting a template argument list. Now, we parse such
constructs tentatively, and back off if the "<" is not present. This
allows us to parse dependent template names as one would use them for,
e.g., template template parameters:

  template<typename T, template<class> class X = T::template apply>
    struct MetaSomething;

Also, test default arguments for template template parameters.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86841 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-11 16:39:34 +00:00
Douglas Gregor 788cd06cf8 Introduce a new representation for template template
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. 



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86777 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-11 01:00:40 +00:00
Douglas Gregor d47c47d65e Make sure that we instantiate default function arguments for an
overloaded operator(). 


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86581 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-09 19:27:57 +00:00
Douglas Gregor 0f8716b7bb Improve instantiation of default template arguments for nested
templates. The instantiation of these default arguments must be (and
now, is) delayed until the template argument is actually used, at
which point we substitute all levels of template arguments
concurrently.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86578 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-09 19:17:50 +00:00
Douglas Gregor 11a82401ea Slightly more testing for instantiation of non-type template parameters in nested templates, for my own sanity's sake
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86570 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-09 18:29:00 +00:00
Sebastian Redl a29e51bb98 Special-case default argument expression in instantiation. This should fix PR4301. Doug, please double-check my assumptions. Read the PR for more details.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86465 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-08 13:56:19 +00:00
Sebastian Redl 42dddbeadb Don't reprocess non-dependent initializers of non-dependent VarDecls. Fixes PR5426.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86460 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-08 10:16:43 +00:00
Daniel Dunbar 4fcfde4d5c Eliminate &&s in tests.
- 'for i in $(find . -type f); do sed -e 's#\(RUN:.*[^ ]\) *&& *$#\1#g' $i | FileUpdate $i; done', for the curious.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86430 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-08 01:45:36 +00:00
Douglas Gregor 3734c21b60 Cope with calls to operator() templates. Fixes PR5419.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86387 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-07 17:23:56 +00:00
Anders Carlsson d8fe2d56fb When instantiating a field decl, make sure to clone its attributes. With this change FileCheck no longer crashes when it's run without any arguments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86344 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-07 06:07:58 +00:00
Douglas Gregor 4912c347ce Make sure that EnumConstantDecls always get a type, even when they have type-dependent initializers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86197 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-06 00:03:12 +00:00
Douglas Gregor c7621a6471 Be a little more careful when trying to extract a TypeDecl from a enum/class/struct/union specifier; in invalid code, we may also see ClassTemplateDecls.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86171 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-05 20:54:04 +00:00
Douglas Gregor c2f38827ba De-FIXME a test
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86166 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-05 20:02:41 +00:00
Douglas Gregor 393896f49d Fixed two places where we needed to force completion of a type
(without complaining if it fails) to get proper semantics: reference
binding with a derived-to-base conversion and the enumeration of
constructors for user-defined conversions. There are probably more
cases to fix, but my prior attempt at statically ensuring that
complete-type checking always happens failed. Perhaps I'll try again.

With this change, Clang can parse include/llvm/*.h!



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86129 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-05 13:06:35 +00:00
Douglas Gregor 6ca7cfb3fb When instantiating a UnaryOperator, allow the resulting expression to
still be dependent or invoke an overloaded operator. Previously, we
only supported builtin operators.

BinaryOperator/CompoundAssignOperator didn't have this issue because
we always built a CXXOperatorCallExpr node, even when name lookup
didn't find any functions to save until instantiation time. Now, that
code builds a BinaryOperator or CompoundAssignOperator rather than a
CXXOperatorCallExpr, to save some space.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86087 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-05 00:51:44 +00:00
Douglas Gregor b1c2ea5ddd Make sure to grab CVR qualifiers from the canonical type. ARGH!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86079 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-05 00:07:36 +00:00
Douglas Gregor 8a4386b363 When instantiating a MemberExpr, be sure to instantiate the
explicitly-specified template arguments, too!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86066 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-04 23:20:05 +00:00
Douglas Gregor 43d8863df9 When starting a C++ member access expression, make sure to compute the
type of the object even when it is dependent. Specifically, this makes
sure that we get the right type for "this->", which is important when
performing name lookup into this scope to determine whether an
identifier or operator-function-id is a template name.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86060 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-04 22:49:18 +00:00
John Thompson 4188aed028 Fixed for running on Windows.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86053 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-04 21:52:17 +00:00
Douglas Gregor ff5243981e Fix a little canonical-types issue with non-type template arguments.
Fixes PR5349. 


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86052 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-04 21:50:46 +00:00
Douglas Gregor 8623541887 Properly replace (cxxscope, template-id) annotation tokens with a
single typename annotation token when backtracing. Fixes PR5350.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86034 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-04 18:18:19 +00:00
Douglas Gregor 1fe6b919f7 Don't try to check the initialization of fields with dependent
types. Fixes PR5352.

Fariborz, please review.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86031 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-04 17:16:11 +00:00
Douglas Gregor c86a6e9881 When performing template instantiation (transformation) of
expressions, keep track of whether we are immediately taking the
address of the expression. Pass this flag when building a declaration
name expression so that we handle pointer-to-member constants
properly.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86017 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-04 07:01:15 +00:00
Douglas Gregor ca1bdd7c26 Implement support for parsing dependent template-ids that refer to
overloaded operators, e.g.,

  p->template operator+<T>()




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85989 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-04 00:56:37 +00:00
Douglas Gregor 014e88d94f Parsing and semantic analysis for template-ids that name overloaded
operators, e.g., 

  operator+<int>

which now works in declarators, id-expressions, and member access
expressions. This commit only implements the non-dependent case, where
we can resolve the template-id to an actual declaration.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85966 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-03 23:16:33 +00:00
Daniel Dunbar d73902121a Switch XFAIL format to match LLVM.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85880 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-03 07:25:45 +00:00
Douglas Gregor 3f9a0566e6 Introduce a new class, UnqualifiedId, that provides a parsed
representation of a C++ unqualified-id, along with a single parsing
function (Parser::ParseUnqualifiedId) that will parse all of the
various forms of unqualified-id in C++.

Replace the representation of the declarator name in Declarator with
the new UnqualifiedId class, simplifying declarator-id parsing
considerably and providing more source-location information to
Sema. In the future, I hope to migrate all of the other
unqualified-id-parsing code over to this single representation, then
begin to merge actions that are currently only different because we
didn't have a unqualified notion of the name in the parser.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85851 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-03 01:35:08 +00:00
Douglas Gregor cf3293eaeb When determining whether a reference to a static data member is an
integral constant expression, make sure to find where the initializer
was provided---inside or outside the class definition---since that can
affect whether we have an integral constant expression (and, we need
to see the initializer itself).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85741 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-01 20:32:48 +00:00
Douglas Gregor 7a34314290 Within a template, qualified name lookup can refer to a non-dependent type
that is not known to be a base class at template definition time due
to some dependent base class. Treat qualified name lookup that refers
to a non-static data member or function as implicit class member
access when the "this" type would be dependent.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85718 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-01 17:08:18 +00:00
Douglas Gregor 550d9b28fd Implement "incremental" template instantiation for non-type template
parameters and template type parameters, which occurs when
substituting into the declarations of member templates inside class
templates. This eliminates errors about our inability to "reduce
non-type template parameter depth", fixing PR5311.

Also fixes a bug when instantiating a template type parameter
declaration in a member template, where we weren't properly reducing
the template parameter's depth.

LLVM's StringSwitch header now parses.




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85669 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-31 17:21:17 +00:00
Douglas Gregor 682054c52e When looking for a copy-assignment operator to determine the cv-qualifiers on its argument type, ignore assignment operator templates
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85629 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-30 22:48:49 +00:00
Douglas Gregor 259571e27e When a friend is declared in a dependent context, don't even try to
match it up with a declaration in the outer scope.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85628 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-30 22:42:42 +00:00
Douglas Gregor e8c01bdb56 Instantiate class template friends better; fixes PR5332.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85612 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-30 21:07:27 +00:00
Douglas Gregor 2685eab9d3 We may need to instantiate a class template specialization as part of a derived-to-base pointer case
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85532 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-29 23:08:22 +00:00
Sebastian Redl f322ed6d39 Properly instantiate usage of overloaded operator []. Fixes PR5345.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85524 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-29 20:17:01 +00:00
Douglas Gregor fd2300e1ee Yet more instantiation-location information. Fixes PR5336.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85516 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-29 17:56:10 +00:00
Anders Carlsson 0ebb6d391d Make sure to call CompleteConstructorCall for bases and members that are initialized implicitly in constructors so that default arguments etc are set correctly. Fixes PR5283.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85510 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-29 15:46:07 +00:00
John Thompson b3eca29e2b Disabling some MS extensions which cause these tests to fail
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85236 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-27 14:31:53 +00:00
Douglas Gregor 972e6ce33c Only set the point of instantiation for an implicit or explicit
instantiation once we have committed to performing the
instantiation. As part of this, make our makeshift
template-instantiation location information suck slightly less.

Fixes PR5264.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85209 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-27 06:26:26 +00:00
Douglas Gregor 3eefb1c4bd Fix overload resolution when calling a member template or taking the
address of a member template when explicit template arguments are
provided.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84991 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-24 04:59:53 +00:00
Douglas Gregor 33642df300 Implement template instantiation for non-type template
parameters. Fixes PR5103.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84979 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-23 23:25:44 +00:00
Douglas Gregor 097bfb1175 Migrate Sema::ActOnCallExpr to Sema::FixOverloadedFunctionReference,
so that we maintain better source information after template argument
deduction and overloading resolves down to a specific
declaration. Found and dealt with a few more cases that 
FixOverloadedFunctionReference didn't cope with.

(Finally) added a test case that puts together this change with the
DeclRefExpr change to (optionally) include nested-name-specifiers and
explicit template argument lists.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84974 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-23 22:18:25 +00:00
John McCall eee91c3efb Rebuild dependently-sized ext vectors if either the element type or the size
changed under the transform.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84953 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-23 17:55:45 +00:00
Douglas Gregor a9e29aa4b1 When a template-id expression refers to a member function template, turn it into an (implicit) member access expression. Fixes PR5220
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84848 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-22 07:19:14 +00:00
Douglas Gregor 6cd219879f Handle substitutions into the "first qualifier in scope" of a
qualified member access expression (e.g., t->U::member) when that
first qualifier refers to a template parameters.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84612 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-20 05:58:46 +00:00
Douglas Gregor dd62b15665 Parse a simple-template-id following a '~' when calling a destructor, e.g.,
t->~T<A0, A1>()

Fixes PR5213.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84545 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-19 22:04:39 +00:00
Douglas Gregor 089407be3f When type-checking a C++ "new" expression, don't type-check the actual
initialization if any of the constructor/initialization arguments are
type-dependent. Fixes PR5224.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84365 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-17 21:40:42 +00:00
Douglas Gregor 89a5bea021 Make the remaining explicit-instantiation semantic action use
CheckSpecializationInstantiationRedecl to check for
redeclarations/instantiations. Also fixes a longstanding issue where
our explicit-instantiation location information wasn't as good as it
could have been.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84216 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-15 22:53:21 +00:00
Douglas Gregor 558c03222c Additional semantic checking for explicit template instantiations,
focusing on the scope- and qualifier-related semantic requirements in
C++ [temp.explicit]p2.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84154 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-14 23:41:34 +00:00
Douglas Gregor 542b548e04 When mapping from an injected-class-name to its corresponding
template, make sure to get the template that corresponds to *this*
declaration of the class template or specialization, rather than the
canonical specialization. Fixes PR5187.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84119 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-14 17:30:58 +00:00
Douglas Gregor d9842d0e6d Implement support for overloaded operator uses that result to a call
to a member operator template. We missed updating this call site when
adding support for function templates; bug exposed by a test for
PR5072.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84111 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-14 16:50:13 +00:00
Douglas Gregor a786fdbf6c Improve diagnostics when the parser encounters a declarator with an
unknown type name, e.g.,

  foo::bar x;

when "bar" does not refer to a type in "foo". 

With this change, the parser now calls into the action to perform
diagnostics and can try to recover by substituting in an appropriate
type. For example, this allows us to easily diagnose some missing
"typename" specifiers, which we now do:

  test/SemaCXX/unknown-type-name.cpp:29:1: error: missing 'typename'
        prior to dependent type name 'A<T>::type'
  A<T>::type A<T>::f() { return type(); }
  ^~~~~~~~~~
  typename 

Fixes PR3990.





git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84053 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-13 23:27:22 +00:00
Douglas Gregor 3f09327b26 Unify our diagnostic printing for errors of the form, "we didn't like
what we found when we looked into <blah>", where <blah> is a
DeclContext*. We can now format DeclContext*'s in nice ways, e.g.,
"namespace N", "the global namespace", "'class Foo'".

This is part of PR3990, but we're not quite there yet.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84028 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-13 21:16:44 +00:00
Douglas Gregor a735b206fd Improve the internal representation and semantic analysis of friend
function templates.

This commit ensures that friend function templates are constructed as
FunctionTemplateDecls rather than partial FunctionDecls (as they
previously were). It then implements template instantiation for friend
function templates, injecting the friend function template only when
no previous declaration exists at the time of instantiation. 

Oh, and make sure that explicit specialization declarations are not
friends.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83970 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-13 14:39:41 +00:00
Douglas Gregor b3ae4fcd43 Diagnose the declaration of explicit specializations after an implicit
instantiation has already been required. To do so, keep track of the
point of instantiation for anything that can be instantiated.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83890 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-12 20:18:28 +00:00
Douglas Gregor d7e5bdb23c When declaring a friend class template, we may end up finding an
injected-class-name (e.g., when we're referring to other
specializations of the current class template). Make sure that we see
the template rather than the injected-class-name. Fixes PR4768.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83672 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-09 21:11:42 +00:00
Douglas Gregor e9374d5e2c Make sure to set the template specialization kind of an explicit
template instantiation of a member function of a class template.
FIXME -= 2;


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83520 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-08 01:19:17 +00:00
Douglas Gregor 2db323294a Keep track of whether a member function instantiated from a member
function of a class template was implicitly instantiated, explicitly
instantiated (declaration or definition), or explicitly
specialized. The same MemberSpecializationInfo structure will be used
for static data members and member classes as well.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83509 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-07 23:56:10 +00:00
Douglas Gregor 1fef4e60e7 Type checking for specializations of member functions of class
templates. Previously, these weren't handled as specializations at
all. The AST for representing these as specializations is still a work
in progress.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83498 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-07 22:35:40 +00:00
Douglas Gregor d5cb8765ad Refactor checking of the scope of explicit template specialization
declarations and explicit template instantiations, improving
diagnostics and making the code usable for function template
specializations (as well as class template specializations and partial
specializations). 


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83436 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-07 00:13:32 +00:00
Douglas Gregor b2f81cf7f8 Make sure to free the explicit template arguments provided for an
explicit instantiation. Also, tighten up reference-count checking to
help catch these issues earlier. Fixes PR5069.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83225 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-01 23:51:25 +00:00
Douglas Gregor 3307475eb0 When overload resolution fails for an overloaded operator, show the
overload candidates (but not the built-in ones). We still rely on the
underlying built-in semantic analysis to produce the initial
diagnostic, then print the candidates following that diagnostic. 

One side advantage of this approach is that we can perform more validation
of C++'s operator overloading with built-in candidates vs. the
semantic analysis for those built-in operators: when there are no
viable candidates, we know to expect an error from the built-in
operator handling code. Otherwise, we are not modeling the built-in
semantics properly within operator overloading. This is checked as:

      assert(Result.isInvalid() && 
             "C++ binary operator overloading is missing
             candidates!");
      if (Result.isInvalid())
        PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false);

The assert() catches cases where we're wrong in a +Asserts build. The
"if" makes sure that, if this happens in a production clang
(-Asserts), we still build the proper built-in operator and continue
on our merry way. This is effectively what happened before this
change, but we've added the assert() to catch more flies.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83175 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-30 21:46:01 +00:00
Douglas Gregor 4831682279 Slightly improve the semantics of extern templates for member functions of class templates
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83063 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-29 14:38:03 +00:00
Douglas Gregor 9d7b35303c Parse a C++ scope specifier followed by a "typename" annotation token as a type name within the declaration specifiers. Fixes PR5061.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82974 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-28 07:26:33 +00:00
Douglas Gregor 182ddf0e5d Improve handling of friend function templates somewhat
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82950 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-28 00:08:27 +00:00
Douglas Gregor fc9cd61f23 Simplify the handling of non-dependent friend class template
specializations such as:

  friend class std::vector<int>;

by using the same code path as explicit specializations, customized to
reference an existing ClassTemplateSpecializationDecl (or build a new
"undeclared" one).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82875 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-26 20:57:03 +00:00
Douglas Gregor d85bea2aff Rework the Parse-Sema interaction for friends to better support friend
class templates. We now treat friend class templates much more like
normal class templates, except that they still get special name lookup
rules. Fixes PR5057 and eliminates a bunch of spurious diagnostics in
<iostream>.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82848 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-26 06:47:28 +00:00
Douglas Gregor 0b60d9e009 Use explicitly-specified template argument lists to help naming
explicit template specializations, when available.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82824 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-25 23:53:26 +00:00
Douglas Gregor db422dffb7 Declarators can now properly represent template-ids, e.g., for
template void f<int>(int);
                ~~~~~~
Previously, we silently dropped the template arguments. With this
change, we now use the template arguments (when available) as the
explicitly-specified template arguments used to aid template argument
deduction for explicit template instantiations.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82806 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-25 21:45:23 +00:00
Douglas Gregor d5a423b279 WIP implementation of explicit instantiation of function templates,
member functions of class template specializations, and static data
members. The mechanics are (mostly) present, but the semantic analysis
is very weak.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82789 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-25 18:43:00 +00:00
Douglas Gregor ce94049b69 Fix checking for a null pointer constant when the expression itself is
value-dependent. Audit (and fixed) all calls to
Expr::isNullPointerConstant() to provide the correct behavior with
value-dependent expressions. Fixes PR5041 and a crash in libstdc++
<locale>.

In the same vein, properly compute value- and type-dependence for
ChooseExpr. Fixes PR4996.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82748 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-25 04:25:58 +00:00
Douglas Gregor 7dfd0fb083 When entering the scope of a declarator, make sure that the scope is
complete (or, possibly causing template instantiation).

Test this via some explicit specializations of member functions.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82732 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-24 23:39:01 +00:00
Douglas Gregor b9aa6b214c WIP implementation of explicit function template specialization. This
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.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82728 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-24 23:14:47 +00:00
Douglas Gregor d85cef5a54 Merge uninstantiated default arguments more carefully, and try not to
complain about specializations of member functions that are not
definitions. Fixes PR4995.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82159 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-17 19:51:30 +00:00
Douglas Gregor e95b409613 Teach Sema::FindInstantiatedDecl to find instantiated RecordDecls even
when we are not instantiating the corresponding "current
instantiation." This happens, e.g., when we are instantiating a
declaration reference that refers into the "current instantiation" but
occurs in a default function argument. The libstdc++ vector default
constructor now instantiates properly.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82069 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-16 18:34:49 +00:00
Douglas Gregor c7e406b2ec Commit test case from PR4655, which tests the canonical-types fix in r81913
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81916 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-15 21:14:05 +00:00
Douglas Gregor 1fdd89ba1d When printing an overload candidate that is a function template specialization,
point at the template and print out its template arguments, e.g.,

ambiguous-ovl-print.cpp:5:8: note: candidate function template specialization
      [with T = int]
  void f(T*, long);




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81907 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-15 20:11:42 +00:00
Douglas Gregor f882574cf6 Add an assertion and a test case, in a fruitless attempt to track down an existing bug
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81885 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-15 18:26:13 +00:00
Douglas Gregor bf4ea56cdc Implement partial ordering of class template partial specializations
(C++ [temp.class.order]).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81866 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-15 16:23:51 +00:00
Douglas Gregor 5d7d375063 Implement partial ordering of function templates when calling a
conversion function.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81807 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-14 23:02:14 +00:00
Douglas Gregor 8a51491d93 Implement partial ordering of function template specializations
(C++ [temp.func.order]). 



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81777 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-14 18:39:43 +00:00
Anders Carlsson 255d6415a6 Fix a bug in getFriendObjectKind where we would clear out all mask bits except IDNS_TagFriend and IDNS_OrdinaryFriend but then check for IDNS_Tag and IDNS_Ordinary.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81730 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-13 23:59:13 +00:00
Douglas Gregor 52604ab71a Slight improvement for extern templates, so that an explicit
instantiation definition can follow an explicit instantiation
declaration. This is as far as I want to go with extern templates now,
but they will still need quite a bit more work to get all of the C++0x
semantics right.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81573 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-11 21:19:12 +00:00
Douglas Gregor 678119abd4 Improve testing for extern temp templates, slightly. We are (properly) suppressing the implicit instantiation of members of extern templates
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81567 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-11 20:35:49 +00:00
Douglas Gregor 6cc1518b9f Cleanup and test C++ default arguments. Improvements include:
- Diagnose attempts to add default arguments to templates (or member
    functions of templates) after the initial declaration (DR217).
  - Improve diagnostics when a default argument is redefined. Now, the
    note will always point at the place where the default argument was
    previously defined, rather than pointing to the most recent
    declaration of the function.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81548 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-11 18:44:32 +00:00
John McCall 9cc7807e16 Track a class template specialization's point of instantiation separately
from its location.  Initialize appropriately.

When implicitly creating a declaration of a class template specialization
after encountering the first reference to it, use the pattern class's
location instead of the location of the first reference.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81515 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-11 07:25:08 +00:00
Douglas Gregor 1cdcc579df When re-entering a template scope, we may be entering a class template
partial specialization rather than a subclass of TemplateDecl. Fixes a
crash in libstdc++ 4.2's <map>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81407 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-10 00:12:48 +00:00
Douglas Gregor 3b6afbb99a Initial stab at implement dependent member references to member
templates, e.g.,
  
  x.template get<T>

We can now parse these, represent them within an UnresolvedMemberExpr
expression, then instantiate that expression node in simple cases.

This allows us to stumble through parsing LLVM's Casting.h.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81300 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-09 00:23:06 +00:00
Anders Carlsson 21e1c4ea0a Reapply 81096, now with a fix. Spot the bug:
for (unsigned i = numargs; i < NumArgs; ++i)
        Args[0] = 0;

;)


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81123 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-06 16:54:02 +00:00
Daniel Dunbar 4355be0758 Revert "Initialize default CXXConstructExpr arguments to 0. Fixes a crash when
destroying the CXXConstructExpr.", this is causing test failures across the
board.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81100 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-06 01:31:23 +00:00
Anders Carlsson 657bff7ff3 Initialize default CXXConstructExpr arguments to 0. Fixes a crash when destroying the CXXConstructExpr.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81096 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-05 22:51:06 +00:00
Anders Carlsson 6bc107b498 Report errors for member functions correctly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81063 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-05 05:38:54 +00:00
Anders Carlsson 25cae7f4b1 Use a separate diagnostic for default function argument expressions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81062 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-05 05:14:19 +00:00
Douglas Gregor 4fe95f99a2 Don't generate any code for an explicit call to a trivial destructor.
Now that parsing, semantic analysis, and (I think) code generation of
pseudo-destructor expressions and explicit destructor calls works,
update the example-dynarray.cpp test to destroy the objects it
allocates and update the test to actually compile + link.
The code seems correct, but the Clang-compiled version dies with a
malloc error. Time to debug!



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81025 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-04 19:04:08 +00:00
Douglas Gregor a71d819bb8 Implement AST, semantics, and CodeGen for C++ pseudo-destructor
expressions, e.g.,

  p->~T()

when p is a pointer to a scalar type. 

We don't currently diagnose errors when pseudo-destructor expressions
are used in any way other than by forming a call.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81009 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-04 17:36:40 +00:00
Douglas Gregor 45f9655819 Parse extern templates, pass that information all the way to Sema,
then drop it on the floor.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80989 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-04 06:33:52 +00:00
Douglas Gregor 81499bbeb2 Implement tree transformations for DeclarationNames. Among other
things, this means that we can properly cope with member access
expressions such as 

  t->operator T()

where T is a template parameter (or other dependent type).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80957 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-03 22:13:48 +00:00
Douglas Gregor c68afe2cbe Improve template instantiation for member access expressions that
involve qualified names, e.g., x->Base::f. We now maintain enough
information in the AST to compare the results of the name lookup of
"Base" in the scope of the postfix-expression (determined at template
definition time) and in the type of the object expression.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80953 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-03 21:38:09 +00:00
Douglas Gregor 2700dcde04 Add a wicked little test-case that illustrates what we have to deal
with to properly support member access expressions in templates. This
test is XFAIL'd, because we get it completely wrong, but I've made the
minimal changes to the representation to at least avoid a crash.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80856 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-02 23:58:38 +00:00
Douglas Gregor 2dd078ae50 Rewrite of our handling of name lookup in C++ member access expressions, e.g.,
x->Base::f

We no longer try to "enter" the context of the type that "x" points
to. Instead, we drag that object type through the parser and pass it
into the Sema routines that need to know how to perform lookup within
member access expressions.

We now implement most of the crazy name lookup rules in C++
[basic.lookup.classref] for non-templated code, including performing
lookup both in the context of the type referred to by the member
access and in the scope of the member access itself and then detecting
ambiguities when the two lookups collide (p1 and p4; p3 and p7 are
still TODO). This change also corrects our handling of name lookup
within template arguments of template-ids inside the
nested-name-specifier (p6; we used to look into the scope of the
object expression for them) and fixes PR4703.

I have disabled some tests that involve member access expressions
where the object expression has dependent type, because we don't yet
have the ability to describe dependent nested-name-specifiers starting
with an identifier.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80843 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-02 22:59:36 +00:00
Douglas Gregor ae44067440 Add a few more typename-specifier tests that involve simple-template-ids in the nested-name-specifier
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80784 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-02 13:07:20 +00:00
Douglas Gregor 6946baf354 When parsing typename specifiers (with either the identifier or
simple-template-id form), check whether the scope specifier is
computable as a declaration context rather than checking whether it is
dependent, so that we properly cope with members of the current
instantiation. 

Improve testing for typename specifiers that terminate in a
simpe-template-id.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80783 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-02 13:05:45 +00:00
Douglas Gregor 44c73848d5 Implement proper substitution for OverloadedFunctionDecls, but substituting each of the functions in the overload set
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80692 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-01 17:53:10 +00:00
Douglas Gregor 8f1d89e40a Fix a crasher involving template instantiation of non-dependent
expressions making use of an overloaded operator. Thanks for the test
case, Anders!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80679 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-01 16:58:52 +00:00
Anders Carlsson cdc83c7779 Don't assume that a base is always a RecordType, it can also be a TemplateSpecializationType. Also, make sure to get the instantiated union member.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80662 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-01 06:22:14 +00:00
Anders Carlsson 9988d5d9ad Handle member initializers that point to fields in anonymous structs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80659 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-01 04:31:02 +00:00
Anders Carlsson d8b285fee4 Don't assert when instantiating member references to fields in anonymous structs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80657 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-01 04:26:58 +00:00
Douglas Gregor c4bf26fbdf Preliminary AST representation and semantic analysis for
explicitly-specified template argument lists in member reference
expressions, e.g.,

  x->f<int>()



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80646 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-01 00:37:14 +00:00
Douglas Gregor f328a2857d Add parsing for references to member function templates with explicit
template argument lists, e.g., x.f<int>().

Semantic analysis will be a separate commit.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80624 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 21:16:32 +00:00
Douglas Gregor 017dde547d Implement template instantiation for member operator access.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80609 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-31 20:00:26 +00:00
Eli Friedman c5573a81a8 Make instantiating initializers for classes with a dependent base type
work correctly.

The change in lib/AST/DeclCXX.cpp is mostly a large reindentation; I 
couldn't figure out a good way to avoid it.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80446 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-29 22:22:07 +00:00
Anders Carlsson 0d8df780ae Improve instantiation of UnresolvedUsingDecls.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80434 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-29 19:37:28 +00:00
John McCall d0b7839f8a Test case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80426 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-29 08:20:44 +00:00
Anders Carlsson 0902531550 Instantiate member and base initializers. Patch by Anders Johnsen! (tweaked slightly by me)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80422 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-29 05:16:22 +00:00
Douglas Gregor a5bf7f13d7 Don't crash when instantiating templates containing anonymous structs/unions
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80397 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-28 22:03:51 +00:00
Douglas Gregor 3cd4d1ece3 Test instantiation of static data members that live within nested
member templates.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80396 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-28 21:41:19 +00:00
Douglas Gregor 8320ad4004 Test instantiations of out-of-line member definitions of nested templates.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80395 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-28 21:15:08 +00:00
Douglas Gregor 5ec178ff23 Fix and test template instantiation for nested member templates.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80394 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-28 21:09:48 +00:00
Douglas Gregor 357bbd022c Tighten up the conversion from a single-level template argument list
to a multi-level template argument list by making it explicit. The
forced auditing of callers found a bug in the instantiation of member
classes inside member templates.

I *love* static type systems.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80391 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-28 20:50:45 +00:00
Douglas Gregor d6350aefb1 Implement template instantiation for member class templates.
When performing template instantiation of the definitions of member
templates (or members thereof),  we build a data structure containing
the template arguments from each "level" of template
instantiation. During template instantiation, we substitute all levels
of template arguments simultaneously. 



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80389 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-28 20:31:08 +00:00
Douglas Gregor d110243321 Collect multiple levels of template arguments into a new type,
MultiLevelTemplateArgumentList. This is a baby step toward
instantiating member templates; no intended functionality change yet.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80380 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-28 17:37:35 +00:00
Fariborz Jahanian 4fc7ab3641 ir-gen related patch for type conversion
with class type conversion methods. WIP.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80365 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-28 15:11:24 +00:00
Eli Friedman eaba1af852 Fix for PR4794 (instantiating friend class decl); this version shouldn't
cause any regressions.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80277 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-27 19:11:42 +00:00
Eli Friedman 56bea43ac1 Back out bad piece of r80272. Will look at fixing this a different way.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80273 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-27 18:44:04 +00:00
Eli Friedman c5c54f2c7b PR4794: Make instantiating friend class decls not crash.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80272 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-27 18:38:56 +00:00
Douglas Gregor d60e105e6d Implement instantiation of the declarations of member function
templates within class templates, producing a member function template
of a class template specialization. If you can parse that, I'm
sorry. Example:

  template<typename T>
  struct X {
    template<typename U> void f(T, U);
  };

When we instantiate X<int>, we now instantiate the declaration
X<int>::f, which looks like this:

  template<typename U> void X<int>::f(int, U);

The path this takes through
TemplateDeclInstantiator::VisitCXXMethodDecl is convoluted and
ugly, but I don't know how to improve it yet. I'm resting my hopes on
the multi-level substitution required to instantiate definitions of
nested templates, which may simplify this code as well.

More testing to come...



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80252 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-27 16:57:43 +00:00
Anders Carlsson 8d4c5ea0ee Don't check member and base initializers if the constructor is dependent.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80211 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-27 05:57:30 +00:00
Douglas Gregor 83ddad3ab5 Implement support for C++ direct initializers that involve dependent
types or type-dependent expressions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80143 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-26 21:14:46 +00:00
Douglas Gregor db3a0f543e Make sure to compare primary declaration contexts when determining whether a declaration is in scope
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80126 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-26 18:54:58 +00:00
Douglas Gregor 42c39f3918 When we know that we are parsing a class-name, implicitly construct a
TypenameType if getTypeName is looking at a member of an unknown
specialization. This allows us to properly parse class templates that
derived from type that could only otherwise be described by a typename type, 
e.g.,

  template<class T> struct X {};
  template<typename T> struct Y : public X<T>::X { }; 

Fixes PR4381.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80123 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-26 18:27:52 +00:00
Douglas Gregor dacd434c49 Improve diagnostics and recovery when the nested-name-specifier of a
qualified name does not actually refer into a class/class
template/class template partial specialization. 

Improve printing of nested-name-specifiers to eliminate redudant
qualifiers. Also, make it possible to output a nested-name-specifier
through a DiagnosticBuilder, although there are relatively few places
that will use this leeway.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80056 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-26 00:04:55 +00:00
Douglas Gregor bc047ba733 Test out-of-line definition of a static data member of a member class of a nested class template. Phew
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80046 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-25 22:54:02 +00:00
Douglas Gregor c131ebb5cb Test out-of-line definitions of static data members of nested member class templates
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80045 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-25 22:53:07 +00:00
Douglas Gregor 495c35d291 Improve support for out-of-line definitions of nested templates and
their members, including member class template, member function
templates, and member classes and functions of member templates.

To actually parse the nested-name-specifiers that qualify the name of
an out-of-line definition of a member template, e.g.,

  template<typename X> template<typename Y>
  X Outer<X>::Inner1<Y>::foo(Y) {
    return X();
  }

we need to look for the template names (e.g., "Inner1") as a member of
the current instantiation (Outer<X>), even before we have entered the
scope of the current instantiation. Since we can't do this in general
(i.e., we should not be looking into all dependent
nested-name-specifiers as if they were the current instantiation), we
rely on the parser to tell us when it is parsing a declaration
specifier sequence, and, therefore, when we should consider the
current scope specifier to be a current instantiation.

Printing of complicated, dependent nested-name-specifiers may be
somewhat broken by this commit; I'll add tests for this issue and fix
the problem (if it still exists) in a subsequent commit.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80044 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-25 22:51:20 +00:00
Douglas Gregor 05396e20d6 Implement out-of-line definitions of nested class templates. Most of
the logic is there for out-of-line definitions with multiple levels of
nested templates, but this is still a work-in-progress: we're having
trouble determining when we should look into a dependent
nested-name-specifier. 


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80003 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-25 17:23:04 +00:00
Fariborz Jahanian c87efbd2cb Skip over bases/fields with dependent types.
Fixes pr4771.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79999 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-25 16:37:49 +00:00
Douglas Gregor 0b84a53412 Add a little more testing for default arguments of constructors in a class template
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79989 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-25 15:24:38 +00:00
Anders Carlsson 5653ca5088 If a parameter has a default argument expression, make sure to instantiate the parameter type before checking that the expression is a valid initializer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79986 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-25 13:46:13 +00:00
Anders Carlsson 8644aecd43 Improved support for default arguments in constructors for class templates.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79984 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-25 13:07:08 +00:00
Anders Carlsson 9351c173cd Basic support for default argument expressions for function templates.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79972 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-25 03:18:48 +00:00
Douglas Gregor c305833807 Keep track of the template parameter depth properly when we have
member templates declared inside other templates. This allows us to
match out-of-line definitions of member function templates within
class templates to the declarations within the class template. We
still can't handle out-of-line definitions for member class templates,
however.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79955 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-24 23:03:25 +00:00
Douglas Gregor 9983cc1104 Don't try to evaluate an expression that is type- or value-dependent while building the CFG
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79941 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-24 21:39:56 +00:00
Fariborz Jahanian 77a2b4f361 Fixes pr4763.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79923 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-24 17:19:23 +00:00
Douglas Gregor 5842ba9fd4 Try to complete a type before looking for conversion functions within
that type. Note that we do not produce a diagnostic if the type is
incomplete; rather, we just don't look for conversion functions. Fixes PR4660.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79919 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-24 15:23:48 +00:00
Douglas Gregor efd5bdad3c Make sure to adjust function template declarations to their templated
declarations (e.g., FunctionTemplateDecl -> CXXConstructorDecl) before
performing semantic analysis on the declarations. Fixes PR4761.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79911 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-24 11:57:43 +00:00
Douglas Gregor d83d04041f Implement delayed parsing for member function templates. Fixes PR4608.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79709 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-22 00:34:47 +00:00
Douglas Gregor 1561248f6c Add test taking the address of a member function template and converting it to a member pointer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79699 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-21 23:32:45 +00:00
Douglas Gregor dec06664a1 Introduce support for constructor templates, which can now be declared
and will participate in overload resolution. Unify the instantiation
of CXXMethodDecls and CXXConstructorDecls, which had already gotten
out-of-sync.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79658 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-21 18:42:58 +00:00
Douglas Gregor 6b90686952 Implement support for calling member function templates, which involves:
- Allowing one to name a member function template within a class
  template and on the right-hand side of a member access expression.
  - Template argument deduction for calls to member function templates.
  - Registering specializations of member function templates (and
  finding them later).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79581 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-21 00:16:32 +00:00
Douglas Gregor 37b372b76a Initial support for parsing and representation of member function templates.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79570 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-20 22:52:58 +00:00
Douglas Gregor d1067e5a0a Implement transformation of template names within the generic tree
transform, then use the result for template instantiation. The generic
transformation fixes a few issues:

  - It copes better with template template parameters and member
  templates (when they're implemented). 
  - The logic used to replace template template parameters with their
  arguments is now centralized in TransformDecl, so that it will apply
  for other declaration-instantiation steps.
  - The error-recovery strategy is normalized now, so that any error
  results in a NULL TemplateName.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78292 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-06 06:41:21 +00:00
Douglas Gregor 37d93e9252 Keep track of the template arguments deduced when matching a class
template partial specialization. Then, use those template arguments
when instantiating members of that class template partial
specialization. Fixes PR4607.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77925 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-02 23:24:31 +00:00
Owen Anderson c9c88b4159 Update for LLVM API change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77722 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-31 20:28:54 +00:00
Douglas Gregor 6f2c46b588 Make canonicalization of overloaded function declarations match the
Itanium C++ ABI's name mangling, since both are related to the notion
of "equivalent" function templates.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77678 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-31 16:07:31 +00:00
Douglas Gregor 4a3f780f4f Canonicalize function parameters
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77676 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-31 15:45:02 +00:00
Douglas Gregor 6ebd15e81a Canonicalization and profiling for overloaded function declarations,
for those extra-esoteric cases. Not that any two given C++ compilers
agree on this test case, but this change gives us a strong definition
of equivalent types.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77664 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-31 05:24:01 +00:00
Douglas Gregor 2ec09f1dc1 Canonicalize dependent extended vector types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77663 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-31 03:54:25 +00:00
Eli Friedman 1503f777d9 Make the check for the linkage of a template handle the case of nested
linkage specifications correctly.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77653 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-31 01:43:05 +00:00
Douglas Gregor 04d4beee4b Build canonical types for dependently-sized array types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77647 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-31 00:23:35 +00:00
Douglas Gregor 9d702ae1cd Canonicalization of dependent C++0x decltype types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77643 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-30 23:36:40 +00:00
Douglas Gregor b197572cf1 Canonicalization for dependent typeof(expr) types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77639 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-30 23:18:24 +00:00
Douglas Gregor c5b8c9b660 What luck! Clang obtains support for refering to members of the
current instantiation when that current instantiation is a class
template partial specialization.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77609 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-30 17:50:56 +00:00
Eli Friedman 59c04373c6 Refactor base/member initializers, and construct them correctly in cases
with dependent types.  Fixes PR4621 and PR4627.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77498 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-29 19:44:27 +00:00
Douglas Gregor 1f27ac6a52 Remove an obsolete kludge based on the previous, completely broken handling of function templates
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77464 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-29 16:15:53 +00:00
Douglas Gregor f61ef4fb9f Test redefinition of class template partial specializations
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77463 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-29 16:13:25 +00:00
Douglas Gregor 828e226ab7 Use the new statement/expression profiling code to unique dependent
template arguments, as in template specialization types. This permits
matching out-of-line definitions of members for class templates that
involve non-type template parameters.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77462 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-29 16:09:57 +00:00
Sebastian Redl ef0cb8e62d Make functional-style casts emit correct messages, and fix a crash-on-invalid.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77451 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-29 13:50:23 +00:00
Owen Anderson 08e252425c Update for LLVM API change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77267 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-27 22:29:56 +00:00
Owen Anderson bc0a2226c7 Update for LLVM API change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77249 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-27 21:00:51 +00:00
Douglas Gregor 65b90055dd When instantiating a variable without an initializer, call
ActOnUninitializedDecl.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77211 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-27 17:43:39 +00:00
Sebastian Redl 9cc11e7003 Implement C++ semantics for C-style and functional-style casts. This regresses Clang extension conversions, like vectors, but allows conversions via constructors and conversion operators.
Add custom conversions to static_cast.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77076 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-25 15:41:38 +00:00
Daniel Dunbar 8bf0ccd4c7 Make having no RUN line a failure.
Doug, please look at decltype-crash and instantiate-function-1.mm, I'm not sure
if they are actually testing the right thing / anything.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77070 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-25 12:47:38 +00:00
Eli Friedman de99a45c12 Slight code reorganization to allow instantiating post-inc/dec.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76807 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-22 22:25:00 +00:00
Douglas Gregor f290e0db83 Fix the problems with template argument deduction and array types for
real. It turns out that we need to actually move all of the qualifiers
up to the array type itself, then recanonicalize the deduced template
argument type.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76788 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-22 21:30:48 +00:00
Douglas Gregor b084a05b35 Canonicalize the types produced by template argument deduction.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76777 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-22 20:25:36 +00:00
Douglas Gregor 1f618a0701 Slighty more testing for template argument deduction with array arguments
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76774 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-22 20:07:21 +00:00
Douglas Gregor 9e9fae4b8a Improve template argument deduction for array types, so that a parameter
const T

can be matched with, e.g.,

  volatile int [5]




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76773 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-22 20:02:25 +00:00
Douglas Gregor 5c7e281d36 Test template instantiation for member functions of class templates defined
out of line.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76740 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-22 15:45:39 +00:00
Mike Stump d1969d803c Prep for new warning.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76709 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-22 00:43:08 +00:00
Argyrios Kyrtzidis e7f38406a3 Re-enable 'test/SemaTemplate/temp_class_spec_neg.cpp', after commenting out the cause of the crash.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76337 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-18 21:18:10 +00:00
Daniel Dunbar fb8e7a6305 Disable this test for now, it has been crashing on linux for weeks.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76328 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-18 19:55:20 +00:00
Daniel Dunbar 839fbc52fa The -disable-free hack didn't work...
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75401 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-11 23:05:12 +00:00
Daniel Dunbar 70b8742bd0 Fix comment, and reduce computational expense of this test.
- I don't see any need for it to be this expensive.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75395 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-11 22:44:48 +00:00
Daniel Dunbar e2a3e9a851 Add -disable-free to this test in the hopes if having it pass on Linux for now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75390 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-11 22:00:53 +00:00
Anders Carlsson 4e579922ad Fix type of 'this' and add a decltype test.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75291 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-10 21:35:09 +00:00
Douglas Gregor cca9e9674a Keep track of more information within the template instantiation stack, e.g.,
by distinguishing between substitution that occurs for template
argument deduction vs. explicitly-specifiad template arguments. This
is used both to improve diagnostics and to make sure we only provide
SFINAE in those cases where SFINAE should apply.

In addition, deal with the sticky issue where SFINAE only considers
substitution of template arguments into the *type* of a function
template; we need to issue hard errors beyond this point, as
test/SemaTemplate/operator-template.cpp illustrates.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74651 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-01 22:01:06 +00:00
Fariborz Jahanian 961743326f Patch to implement template types in ctor-initializer list.
Also has fix for bugzilla-4469.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74631 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-01 19:21:19 +00:00
Douglas Gregor b33fe2ff12 When recursively instantiating function templates, keep track of the
instantiation stack so that we provide a full instantiation
backtrace. Previously, we performed all of the instantiations implied
by the recursion, but each looked like a "top-level" instantiation.

The included test case tests the previous fix for the instantiation of
DeclRefExprs. Note that the "instantiated from" diagnostics still
don't tell us which template arguments we're instantiating with.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74540 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-30 17:20:14 +00:00
Douglas Gregor 364e021e8c Improve support for overloaded operator templates.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74390 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-27 21:05:07 +00:00
Eli Friedman 5d39dee0cc Fix a bogus error overloading an operator where the only class
parameter has a dependent type.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74380 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-27 05:59:59 +00:00
Douglas Gregor 1637be727f Implicit instantiation for function template specializations.
For a FunctionDecl that has been instantiated due to template argument
deduction, we now store the primary template from which it was
instantiated and the deduced template arguments. From this
information, we can instantiate the body of the function template.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74232 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-26 00:10:03 +00:00
Douglas Gregor e53060fa78 Improved semantic analysis and AST respresentation for function
templates.

For example, this now type-checks (but does not instantiate the body
of deref<int>):

  template<typename T> T& deref(T* t) { return *t; }

  void test(int *ip) {
    int &ir = deref(ip);
  }

Specific changes/additions:
  * Template argument deduction from a call to a function template.
  * Instantiation of a function template specializations (just the
  declarations) from the template arguments deduced from a call.
  * FunctionTemplateDecls are stored directly in declaration contexts
  and found via name lookup (all forms), rather than finding the
  FunctionDecl and then realizing it is a template. This is
  responsible for most of the churn, since some of the core
  declaration matching and lookup code assumes that all functions are
  FunctionDecls.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74213 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-25 22:08:12 +00:00
Douglas Gregor e542c862bd Start propagating template parameter lists to the right places to
handle function templates. There's no actual code for function
templates yet, but at least we complain about typedef templates.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74021 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-23 23:11:28 +00:00
Douglas Gregor d7b9e9fe54 Some semantic tests for implicit instantiations
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73924 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-22 23:57:29 +00:00
Douglas Gregor 4c4f7cb3a5 Robustify a bunch of C++-related declaration actions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73918 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-22 23:20:33 +00:00
Douglas Gregor d7f37bf8b9 Implement implicit instantiation of the member functions of a class template
specialization. At present, all implicit instantiations occur at the
end of the translation unit.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73915 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-22 23:06:13 +00:00
Douglas Gregor c19ee3eb08 Diagnose class members that shadow a template parameter. Fixes
<rdar://problem/6952203>. 

To do this, we actually remove a not-quite-correct optimization in the
C++ name lookup routines. We'll revisit this optimization for the
general case once more C++ is working.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73659 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-17 23:37:01 +00:00
Douglas Gregor 9cdda0cf85 Support dependent extended vector types and template instantiation
thereof. Patch by Anders Johnsen!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73641 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-17 21:51:59 +00:00
Douglas Gregor 5e9f35c7cb Update LLVM.
Implement support for C++ Substitution Failure Is Not An Error
(SFINAE), which says that errors that occur during template argument
deduction do *not* produce diagnostics and do not necessarily make a
program ill-formed. Instead, template argument deduction silently
fails. This is currently implemented for template argument deduction
during matching of class template partial specializations, although
the mechanism will also apply to template argument deduction for
function templates. The scheme is simple:

  - If we are in a template argument deduction context, any diagnostic
    that is considered a SFINAE error (or warning) will be
    suppressed. The error will be propagated up the call stack via the
    normal means.
  - By default, all warnings and errors are SFINAE errors. Add the
    NoSFINAE class to a diagnostic in the .td file to make it a hard
    error (e.g., for access-control violations).

Note that, to make this fully work, every place in Sema that emits an
error *and then immediately recovers* will need to check
Sema::isSFINAEContext() to determine whether it must immediately
return an error rather than recovering.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73332 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-14 07:33:30 +00:00
Douglas Gregor 247baca66c Move a bunch of tests into temp.param, and write a few tests for paragraphs that hadn't been touched before
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73288 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-13 06:59:07 +00:00
Eli Friedman 923f7534c5 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.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73285 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-13 04:51:30 +00:00
Anders Carlsson 31a08752ed If a CXXRecordDecl is a class template, the 'this' type should be the injected class name type. Fixes pr4383.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73284 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-13 02:59:33 +00:00
Anders Carlsson 0ceffb51b2 More work on type parameter packs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73281 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-13 02:08:00 +00:00
Douglas Gregor 031a5880e1 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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73274 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-13 00:26:55 +00:00
Anders Carlsson 49d2557add A parameter pack must always come last in a class template.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73269 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-12 23:20:15 +00:00
Anders Carlsson ce5635a100 Address more comments from Doug.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73267 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-12 23:09:56 +00:00
Anders Carlsson 9c4c5c8e17 Parameter packs can't have default arguments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73262 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-12 22:30:13 +00:00
Douglas Gregor 16df850bb7 Finish implementing checking of class template partial specializations
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73260 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-12 22:21:45 +00:00
Douglas Gregor 6aa75cfbdd 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.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73259 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-12 22:08:06 +00:00
Douglas Gregor e94866ffc1 Diagnose the incorrect use of non-type template arguments for class
template partial specializations.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73254 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-12 21:21:02 +00:00
Anders Carlsson 941df7dac2 Parse support for C++0x type parameter packs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73247 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-12 19:58:00 +00:00
Douglas Gregor ba1ecb564c Verify that the template parameters of a class template partial
specialization do not have default arguments 
(C++ [temp.class.spec]p10). 


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73245 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-12 19:43:02 +00:00
Anders Carlsson 1d79faf915 Fix PR4365.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73240 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-12 18:53:02 +00:00
Anders Carlsson 859ba504e7 Deducation and instantiation of block types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73232 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-12 16:23:10 +00:00
Douglas Gregor 02cbbd2d94 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.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73196 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-11 18:10:32 +00:00
Anders Carlsson 3b56c00259 Add a null check that fixes the crash in PR4362, and make sure to instantiate non-type template arguments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73193 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-11 16:06:49 +00:00