Commit Graph

338 Commits

Author SHA1 Message Date
Douglas Gregor 2208a2912c 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).

llvm-svn: 82875
2009-09-26 20:57:03 +00:00
Douglas Gregor 3dad842b35 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>.

llvm-svn: 82848
2009-09-26 06:47:28 +00:00
Douglas Gregor 0e876e0180 Use explicitly-specified template argument lists to help naming
explicit template specializations, when available.

llvm-svn: 82824
2009-09-25 23:53:26 +00:00
Douglas Gregor d90fd526d3 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.

llvm-svn: 82806
2009-09-25 21:45:23 +00:00
Douglas Gregor 450f0084a2 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.

llvm-svn: 82789
2009-09-25 18:43:00 +00:00
Douglas Gregor 56751b5981 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.

llvm-svn: 82748
2009-09-25 04:25:58 +00:00
Douglas Gregor 5013a7e42d 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.

llvm-svn: 82732
2009-09-24 23:39:01 +00:00
Douglas Gregor 3a923c2d37 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.

llvm-svn: 82728
2009-09-24 23:14:47 +00:00
Douglas Gregor 4f15f4dec1 Merge uninstantiated default arguments more carefully, and try not to
complain about specializations of member functions that are not
definitions. Fixes PR4995.

llvm-svn: 82159
2009-09-17 19:51:30 +00:00
Douglas Gregor 64621e6eb3 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.

llvm-svn: 82069
2009-09-16 18:34:49 +00:00
Douglas Gregor 45068b3e29 Commit test case from PR4655, which tests the canonical-types fix in r81913
llvm-svn: 81916
2009-09-15 21:14:05 +00:00
Douglas Gregor 4fb9cde8ef 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);

llvm-svn: 81907
2009-09-15 20:11:42 +00:00
Douglas Gregor 31fae89497 Add an assertion and a test case, in a fruitless attempt to track down an existing bug
llvm-svn: 81885
2009-09-15 18:26:13 +00:00
Douglas Gregor be999390eb Implement partial ordering of class template partial specializations
(C++ [temp.class.order]).

llvm-svn: 81866
2009-09-15 16:23:51 +00:00
Douglas Gregor 6010da024c Implement partial ordering of function templates when calling a
conversion function.

llvm-svn: 81807
2009-09-14 23:02:14 +00:00
Douglas Gregor 0ff7d92048 Implement partial ordering of function template specializations
(C++ [temp.func.order]). 

llvm-svn: 81777
2009-09-14 18:39:43 +00:00
Anders Carlsson 40a90c8754 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.
llvm-svn: 81730
2009-09-13 23:59:13 +00:00
Douglas Gregor 4aa04b155a 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.

llvm-svn: 81573
2009-09-11 21:19:12 +00:00
Douglas Gregor dd3f5f1fca Improve testing for extern temp templates, slightly. We are (properly) suppressing the implicit instantiation of members of extern templates
llvm-svn: 81567
2009-09-11 20:35:49 +00:00
Douglas Gregor c732aba9a9 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.

llvm-svn: 81548
2009-09-11 18:44:32 +00:00
John McCall 1806c2795b 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.

llvm-svn: 81515
2009-09-11 07:25:08 +00:00
Douglas Gregor e61ef62cc2 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>.

llvm-svn: 81407
2009-09-10 00:12:48 +00:00
Douglas Gregor 308047d3a5 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.

llvm-svn: 81300
2009-09-09 00:23:06 +00:00
Anders Carlsson faf1ced5ee Reapply 81096, now with a fix. Spot the bug:
for (unsigned i = numargs; i < NumArgs; ++i)
        Args[0] = 0;

;)

llvm-svn: 81123
2009-09-06 16:54:02 +00:00
Daniel Dunbar 94bcae46d5 Revert "Initialize default CXXConstructExpr arguments to 0. Fixes a crash when
destroying the CXXConstructExpr.", this is causing test failures across the
board.

llvm-svn: 81100
2009-09-06 01:31:23 +00:00
Anders Carlsson 8284d7caa3 Initialize default CXXConstructExpr arguments to 0. Fixes a crash when destroying the CXXConstructExpr.
llvm-svn: 81096
2009-09-05 22:51:06 +00:00
Anders Carlsson dc6d2c3cda Report errors for member functions correctly.
llvm-svn: 81063
2009-09-05 05:38:54 +00:00
Anders Carlsson 657bad441e Use a separate diagnostic for default function argument expressions.
llvm-svn: 81062
2009-09-05 05:14:19 +00:00
Douglas Gregor d94105a1c2 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!

llvm-svn: 81025
2009-09-04 19:04:08 +00:00
Douglas Gregor ad8a336b40 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.

llvm-svn: 81009
2009-09-04 17:36:40 +00:00
Douglas Gregor 43e75176ec Parse extern templates, pass that information all the way to Sema,
then drop it on the floor.

llvm-svn: 80989
2009-09-04 06:33:52 +00:00
Douglas Gregor f816bd70ce 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).

llvm-svn: 80957
2009-09-03 22:13:48 +00:00
Douglas Gregor 2b6ca46c6b 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.

llvm-svn: 80953
2009-09-03 21:38:09 +00:00
Douglas Gregor 64792e021d 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.

llvm-svn: 80856
2009-09-02 23:58:38 +00:00
Douglas Gregor b7bfe79412 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.

llvm-svn: 80843
2009-09-02 22:59:36 +00:00
Douglas Gregor 2575dfc7ff Add a few more typename-specifier tests that involve simple-template-ids in the nested-name-specifier
llvm-svn: 80784
2009-09-02 13:07:20 +00:00
Douglas Gregor 12bbfe1d31 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.

llvm-svn: 80783
2009-09-02 13:05:45 +00:00
Douglas Gregor 2ffd96549d Implement proper substitution for OverloadedFunctionDecls, but substituting each of the functions in the overload set
llvm-svn: 80692
2009-09-01 17:53:10 +00:00
Douglas Gregor 32e2c8472e Fix a crasher involving template instantiation of non-dependent
expressions making use of an overloaded operator. Thanks for the test
case, Anders!

llvm-svn: 80679
2009-09-01 16:58:52 +00:00
Anders Carlsson bcec05c9fd 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.
llvm-svn: 80662
2009-09-01 06:22:14 +00:00
Anders Carlsson 17dc7e2007 Handle member initializers that point to fields in anonymous structs.
llvm-svn: 80659
2009-09-01 04:31:02 +00:00
Anders Carlsson 5da848427a Don't assert when instantiating member references to fields in anonymous structs.
llvm-svn: 80657
2009-09-01 04:26:58 +00:00
Douglas Gregor 84f14dd674 Preliminary AST representation and semantic analysis for
explicitly-specified template argument lists in member reference
expressions, e.g.,

  x->f<int>()

llvm-svn: 80646
2009-09-01 00:37:14 +00:00
Douglas Gregor fbc1823451 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.

llvm-svn: 80624
2009-08-31 21:16:32 +00:00
Douglas Gregor f14b46f9a8 Implement template instantiation for member operator access.
llvm-svn: 80609
2009-08-31 20:00:26 +00:00
Eli Friedman 15e05261d4 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.

llvm-svn: 80446
2009-08-29 22:22:07 +00:00
Anders Carlsson 4bb87ce33e Improve instantiation of UnresolvedUsingDecls.
llvm-svn: 80434
2009-08-29 19:37:28 +00:00
John McCall 9dc2aa0c45 Test case.
llvm-svn: 80426
2009-08-29 08:20:44 +00:00
Anders Carlsson 705539441b Instantiate member and base initializers. Patch by Anders Johnsen! (tweaked slightly by me)
llvm-svn: 80422
2009-08-29 05:16:22 +00:00
Douglas Gregor f3db003358 Don't crash when instantiating templates containing anonymous structs/unions
llvm-svn: 80397
2009-08-28 22:03:51 +00:00