Commit Graph

163 Commits

Author SHA1 Message Date
Douglas Gregor fbe6d079e2 More testing of explicit specializations
llvm-svn: 83440
2009-10-07 00:45:53 +00:00
Douglas Gregor 548886518d 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). 

llvm-svn: 83436
2009-10-07 00:13:32 +00:00
Douglas Gregor 27c26e9a09 Test explicit specialization for all of the various cases where
explicit specializations can occur. Also, fix a minor recovery bug
where we should allow declarations coming from the parser to be NULL.

llvm-svn: 83416
2009-10-06 21:27:51 +00:00
Douglas Gregor 42909754f6 Improve template argument deduction in the case where the parameter
type is a template-id (e.g., basic_ostream<CharT, Traits>) and the
argument type is a class that has a derived class matching the
parameter type. Previously, we were giving up on template argument
deduction too early.

llvm-svn: 83177
2009-09-30 22:13:51 +00:00
Douglas Gregor 5ad7c54bb9 Make sure that out-of-line function and variable definitions are not
pushed into scope. Fixes PR5056.

llvm-svn: 83003
2009-09-28 18:41:37 +00:00
Douglas Gregor 9acb690827 Fix name lookup for friend class templates to consider anything in a
scope *up to and including* the innermost namespace scope, rather than
just searching in the innermost namespace scope. 

llvm-svn: 82849
2009-09-26 07:05:09 +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
Daniel Dunbar 81fff1c358 Spell clang-cc correctly.
llvm-svn: 82582
2009-09-22 22:30:59 +00:00
Anders Carlsson e7e163cc0b When creating function types, remove any top-level CVR qualifications in the function type argument types.
llvm-svn: 82093
2009-09-16 23:47:08 +00:00
John McCall 11083da4d0 Improved representation and support for friend class templates. Angst about same.
llvm-svn: 82088
2009-09-16 22:47:08 +00:00
Douglas Gregor 87f5406081 When implicitly declaring operators new, new[], delete, and delete[],
give them the appropriate exception specifications. This,
unfortunately, requires us to maintain and/or implicitly generate
handles to namespace "std" and the class "std::bad_alloc". However,
every other approach I've come up with was more hackish, and this
standard requirement itself is quite the hack.

Fixes PR4829.

llvm-svn: 81939
2009-09-15 22:30:29 +00:00
Douglas Gregor 00a511f0c1 Slightly improved template argument deduction for use in partial
ordering, along with another test case for partial ordering of partial
specializations. 

llvm-svn: 81869
2009-09-15 16:51:42 +00:00
John McCall 27b5c253d8 Skeletal support for friend class templates.
llvm-svn: 81801
2009-09-14 21:59:20 +00:00
Douglas Gregor e1d2ef3508 Refactor MarkDeductedTemplateParameters into
MarkUsedTemplateParameters, which is able to mark template parameters
used within non-deduced contexts as well as deduced contexts. Use this
to finish the implementation of [temp.deduct.partial]p11.

llvm-svn: 81794
2009-09-14 21:25:05 +00:00
Douglas Gregor 406f634df5 Tighten up checking of non-dependent arguments as part of template
argument deduction. This fixes the new test case (since partial
ordering does not have a "verify the results of deduction" step), and
will allow failed template argument deductions to return more quickly
for, e.g., matching class template partial specializations.

llvm-svn: 81779
2009-09-14 20:00:47 +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
Douglas Gregor cc2427c343 When performing name lookup within a class template or class template
partial specialization, make sure we look into non-dependent base
classes (but not dependent base classes). Fixes PR4951.

llvm-svn: 81584
2009-09-11 22:57:37 +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
John McCall e1f2ec28d8 When stringizing a NamedDecl for a diagnostic, treat the template
specialization types differently.

llvm-svn: 81512
2009-09-11 06:45:03 +00:00
John McCall 7f41d98928 Support elaborated dependent types and diagnose tag mismatches.
llvm-svn: 81504
2009-09-11 04:59:25 +00:00
John McCall d8fe9af3a2 Support templateids in friend declarations. Fixes bug 4859.
llvm-svn: 81233
2009-09-08 17:47:29 +00:00
John McCall 06f6fe8df7 Correctly handle elaborated template ids. Still not handled properly for friends.
llvm-svn: 80977
2009-09-04 01:14:41 +00:00
John McCall f8bd861ce9 Borrow a friend class's previous declaration's access specifier regardless of
whether the current context is dependent.

Thanks to Anders for pointing this out.

llvm-svn: 80828
2009-09-02 19:32:14 +00:00
John McCall e94dd7ccf5 When adding a friend class declaration to the lookup tables, use the access specifier
of any previous declaration in case we replace it in a class's declaration table.
Fixes bug 4858.  This sort of thing makes me reconsider putting friend declarations in
declaration lists.

llvm-svn: 80750
2009-09-02 02:15:17 +00:00
John McCall e8dbaef730 Fix a little crasher in friend decls. Thanks again to Eli for finding this.
llvm-svn: 80748
2009-09-02 01:07:03 +00:00
John McCall 2dc078f24e Ensure that the tag decls of friend decls aren't added to the friending class's
decl list, and remove some workarounds that were due to this.  Thanks to Eli for
pointing this out and providing the test case.

llvm-svn: 80745
2009-09-02 00:55:30 +00:00
John McCall 759e32bdc6 Fix bug 4784 and allow friend declarations to properly extend
existing declaration chains.

llvm-svn: 80636
2009-08-31 22:39:49 +00:00
John McCall e3e2047873 Fix a last-minute typo and make the test not emit temporaries.
llvm-svn: 80419
2009-08-29 03:28:20 +00:00
John McCall 970d530a84 Ensure code generation for friend declarations in class templates.
llvm-svn: 80418
2009-08-29 03:16:09 +00:00
John McCall aa74a0c3b5 Omnibus friend decl refactoring. Instead of cloning AST classes for friend
declarations of same, introduce a single AST class and add appropriate bits
(encoded in the namespace) for whether a decl is "real" or not.  Much hackery
about previously-declared / not-previously-declared, but it's essentially
mandated by the standard that friends alter lookup, and this is at least
fairly non-intrusive.

Refactor the Sema methods specific to friends for cleaner flow and less nesting.

Incidentally solve a few bugs, but I remain confident that we can put them back.

llvm-svn: 80353
2009-08-28 07:59:38 +00:00
Anders Carlsson 5a9c5acf0f More work on using declarations.
llvm-svn: 80333
2009-08-28 03:35:18 +00:00
Anders Carlsson 59140b3b86 Many improvements to using declarations.
llvm-svn: 80332
2009-08-28 03:16:11 +00:00
Douglas Gregor e985a3b724 When checking whether one declaration context encloses another, make sure to look at the primary contexts. Thanks to Eli for the test case
llvm-svn: 80212
2009-08-27 06:03:53 +00:00
Douglas Gregor c190523d7a When a member reference expression includes a qualifier on the member
name, e.g.,
  
  x->Base::f()

retain the qualifier (and its source range information) in a new
subclass of MemberExpr called CXXQualifiedMemberExpr. Provide
construction, transformation, profiling, printing, etc., for this new
expression type.

When a virtual function is called via a qualified name, don't emit a
virtual call. Instead, call that function directly. Mike, could you
add a CodeGen test for this, too?

llvm-svn: 80167
2009-08-26 22:36:53 +00:00
Douglas Gregor 053f691d5e 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.

llvm-svn: 80056
2009-08-26 00:04:55 +00:00
John McCall 1dfa9a9872 Modify an assert to capture the restriction on friend declarations more
accurately.  Prevents the assert from triggering incorrectly when friending 
functions first declared in extern "C" contexts.  Fixes bug 4757.

llvm-svn: 80016
2009-08-25 17:53:59 +00:00
Daniel Dunbar 0ad0c21248 Tests for C++ lex.trigraph, patch by Mats!
llvm-svn: 79841
2009-08-23 08:22:33 +00:00
Chris Lattner d99bd52c73 Eli points out that we really must diagnose "void* > 0" as an extension.
Explicitly add it as an EXTENSION instead of an EXTWARN so that it only
comes out with -pedantic.  Thanks Eli!

llvm-svn: 79791
2009-08-23 00:03:44 +00:00
Douglas Gregor c45a40afd1 Implement delayed parsing for member function templates. Fixes PR4608.
llvm-svn: 79709
2009-08-22 00:34:47 +00:00
Douglas Gregor 05155d8d7b Implement conversion function templates, along with the ability to use
template argument deduction from a conversion function (C++
[temp.deduct.conv]) with implicit conversions.

llvm-svn: 79693
2009-08-21 23:19:43 +00:00
Douglas Gregor e839486de9 Refactor instantiation of destructors to use the common CXXMethodDecl
code, fixing a problem where instantiations of out-of-line destructor
definitions would had the wrong lexical context.

Introduce tests for out-of-line definitions of the constructors,
destructors, and conversion functions of a class template partial
specialization.

llvm-svn: 79682
2009-08-21 22:43:28 +00:00
Douglas Gregor 25e8e363df Add test for out-of-line definition of a conversion function
llvm-svn: 79679
2009-08-21 22:23:24 +00:00
Douglas Gregor e5bbb7d4ef Fix parsing for out-of-line definitions of constructors and
destructors of class templates.

llvm-svn: 79678
2009-08-21 22:16:40 +00:00
John McCall 87a44eb98a Basic nested-template implementation.
llvm-svn: 79504
2009-08-20 01:44:21 +00:00
John McCall 58de35804b Support friend declarations in templates and test that argdep lookup
still works.

llvm-svn: 78979
2009-08-14 02:03:10 +00:00
John McCall d1e9d835f3 Argument-dependent lookup for friend declarations. Add a new decl type,
FriendFunctionDecl, and create instances as appropriate.

The design of FriendFunctionDecl is still somewhat up in the air;  you can
befriend arbitrary types of functions --- methods, constructors, etc. ---
and it's not clear that this representation captures that very well.
We'll have a better picture when we start consuming this data in access
control.

llvm-svn: 78653
2009-08-11 06:59:38 +00:00
John McCall 93343b9466 Permit a class to friend its members in C++0x, without restriction.
Permit a class to friend its class members in C++ 98, as long as extensions
are enabled (and even when they aren't, only give an extwarn about it).

llvm-svn: 78332
2009-08-06 20:49:32 +00:00
Douglas Gregor 15acfb9f50 When we encounter a dependent type that was parsed before we know that
we were going to enter into the scope of a class template or class
template partial specialization, rebuild that type so that it can
refer to members of the current instantiation, as in code like

  template<typename T>
  struct X {
    typedef T* pointer;
    pointer data();
  };

  template<typename T>
  typename X<T>::pointer X<T>::data() { ... }

Without rebuilding the return type of this out-of-line definition, the
canonical return type of the out-of-line definition (a TypenameType)
will not match the canonical return type of the declaration (the
canonical type of T*).

llvm-svn: 78316
2009-08-06 16:20:37 +00:00
John McCall 07e91c04ba First pass at friend semantics.
llvm-svn: 78274
2009-08-06 02:15:43 +00:00
John McCall 9de556c8b6 AlisdairM pointed out that this will likely be relaxed in C++0x, so let's
make a note of it in the test case.

llvm-svn: 78266
2009-08-06 00:50:46 +00:00
John McCall 13c5a27c9a Add a test for invalid uses of non-static members from nested classes, just
because I was thinking about it.

llvm-svn: 78262
2009-08-05 23:56:26 +00:00
Douglas Gregor ef4e4cca07 Make the recanonicalization-for-an-out-of-line-definition test case a bit trickier
llvm-svn: 77707
2009-07-31 18:36:42 +00:00
Douglas Gregor 1530138fd0 Support out-of-line definitions of the members of class template
partial specializations.

llvm-svn: 77606
2009-07-30 17:40:51 +00:00
Douglas Gregor 0004417e81 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.

llvm-svn: 77462
2009-07-29 16:09:57 +00:00
Douglas Gregor 8ce432e9eb Add a template test that requires canonical expression comparison
llvm-svn: 77325
2009-07-28 16:39:54 +00:00
Owen Anderson e05f2ed478 Update for LLVM API change.
llvm-svn: 77249
2009-07-27 21:00:51 +00:00
Daniel Dunbar 595c98729b 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.

llvm-svn: 77070
2009-07-25 12:47:38 +00:00
John McCall 02dee0a46a Semantic checking for main().
Fix some invalid main() methods in the test suite that were nicely
exposed by the new checks.

llvm-svn: 77047
2009-07-25 04:36:53 +00:00
Douglas Gregor a6ef8f0813 Template instantiation for static data members that are defined out-of-line.
Note that this also fixes a bug that affects non-template code, where we 
were not treating out-of-line static data members are "file-scope" variables,
and therefore not checking their initializers.

llvm-svn: 77002
2009-07-24 20:34:43 +00:00
Douglas Gregor e93e46c690 Implement support for out-of-line definitions of the class members of class
templates, e.g.,

  template<typename T>
  struct Outer {
    struct Inner;
  };

  template<typename T>
  struct Outer<T>::Inner {
    // ...
  };

Implementing this feature required some extensions to ActOnTag, which
now takes a set of template parameter lists, and is the precursor to
removing the ActOnClassTemplate function from the parser Action
interface. The reason for this approach is simple: the parser cannot
tell the difference between a class template definition and the
definition of a member of a class template; both have template
parameter lists, and semantic analysis determines what that template
parameter list means.

There is still some cleanup to do with ActOnTag and
ActOnClassTemplate. This commit provides the basic functionality we
need, however.

llvm-svn: 76820
2009-07-22 23:48:44 +00:00
Mike Stump af6ab88979 Prep for new warning.
llvm-svn: 76772
2009-07-22 20:02:03 +00:00
Douglas Gregor 8a27391190 "This patch implements the restrictions on union members detailed in
[class.union]p1", from John McCall!

llvm-svn: 76766
2009-07-22 18:25:24 +00:00
Douglas Gregor b09f3d82cc Implement parsing and semantic analysis for out-of-line definitions of static
data members of class templates. We don't instantiate the definitions yet,
however.

llvm-svn: 76756
2009-07-22 17:18:37 +00:00
Douglas Gregor a3a4dd5d03 Test template instantiation for member functions of class templates defined
out of line.

llvm-svn: 76740
2009-07-22 15:45:39 +00:00
Douglas Gregor 168190d822 Complain if we're entering the context of a dependent nested-name-specifier but
cannot match that nested-name-specifier to a class template or class template
partial specialization.

llvm-svn: 76704
2009-07-22 00:28:09 +00:00
Douglas Gregor d8d297c0ac Basic parsing and semantic analysis for out-of-line definitions of the
member functions of class templates, e.g.,

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

  template<typename T> X<T>::f(T) { /* ... */ }

llvm-svn: 76692
2009-07-21 23:53:31 +00:00
Mike Stump 0ab3c3deac Revert this, we have a better way to do this.
llvm-svn: 76687
2009-07-21 23:47:12 +00:00
Mike Stump d8679446a3 Revert this, we have a better way to handle this.
llvm-svn: 76685
2009-07-21 23:45:39 +00:00
Mike Stump df3f1447e4 Prep for new warning.
llvm-svn: 76640
2009-07-21 21:03:09 +00:00
Mike Stump f4464156cf Prep for new warning.
llvm-svn: 76628
2009-07-21 19:03:43 +00:00
Mike Stump 447351f1ff Prep for new warning.
llvm-svn: 76627
2009-07-21 19:02:55 +00:00
Daniel Dunbar 631a57e30f Fix test case to match intent.
llvm-svn: 75381
2009-07-11 20:17:35 +00:00
Anders Carlsson 43171d6aeb Add another test.
llvm-svn: 75324
2009-07-11 00:55:33 +00:00
Anders Carlsson ae01993a12 Implement more of C++0x 'auto'. A variable with an auto type specifier must have an initializer. Also, move some tests around to match the C++0x draft better.
llvm-svn: 75322
2009-07-11 00:34:39 +00:00
Douglas Gregor b05ce0f395 Another little test for C++ [over.over]
llvm-svn: 75151
2009-07-09 17:44:05 +00:00
Douglas Gregor 6b6ba8bad8 Add test for C++ [over.over.]p1, the contexts in which one can take the address of an overloaded function.
llvm-svn: 75146
2009-07-09 17:16:51 +00:00
Anders Carlsson 03f89b1828 Store the isAddressOfOperand in the UnresolvedDeclRefExpr, so that we can pass it when instantiating the expr. Fixes another member pointer bug.
llvm-svn: 75075
2009-07-09 00:05:08 +00:00
Douglas Gregor b257e4fff8 Implement the simple form of overload resolution used when taking the
address of an overloaded function (which may involve both functions
and function templates). 

llvm-svn: 75069
2009-07-08 23:33:52 +00:00
Anders Carlsson 0b675f5ad5 It's not allowed to form member pointers to members that have reference type. Add a test for this and the rest of [dcl.mptr]p3.
llvm-svn: 75054
2009-07-08 21:45:58 +00:00
Douglas Gregor 9b14658713 Implement template argument deduction when taking the address of a
function template. Most of the change here is in factoring out the
common bits used for template argument deduction from a function call
and when taking the address of a function template.

llvm-svn: 75044
2009-07-08 20:55:45 +00:00
Douglas Gregor be759256b9 Fix a corner case with argument-dependent lookup and overloaded function sets.
llvm-svn: 74999
2009-07-08 10:57:20 +00:00
Douglas Gregor 197e5f7bb7 Improve argument-dependent lookup to find associated classes and
namespaces based on the template arguments of a class template
specialization type.

llvm-svn: 74993
2009-07-08 07:51:57 +00:00
Douglas Gregor d3cb356d14 Overload resolution prefers non-templates to templates
llvm-svn: 74971
2009-07-07 23:38:56 +00:00
Douglas Gregor e81f3e71f8 Improve template argument deduction from a call. In particular,
implement C++ [temp.deduct.call]p3b3, which allows a template-id
parameter to match a derived class of the argument, while deducing
template arguments.

llvm-svn: 74965
2009-07-07 23:09:34 +00:00
Ted Kremenek 71bf4264bf Fix RUN line so this test doesn't hang.
llvm-svn: 74719
2009-07-02 18:44:31 +00:00
Douglas Gregor ff6cbdf806 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.

llvm-svn: 74651
2009-07-01 22:01:06 +00:00
Douglas Gregor e3f1f350ff Cope with explicitly-specified function template arguments when there
are fewer template arguments than there are template parameters for
that function.

llvm-svn: 74578
2009-07-01 00:28:38 +00:00
Douglas Gregor 89026b5018 When explicit template arguments are provided for a function call,
substitute those template arguments into the function parameter types
prior to template argument deduction. There's still a bit of work to
do to make this work properly when only some of the template arguments
are specified.

llvm-svn: 74576
2009-06-30 23:57:56 +00:00
Douglas Gregor a727cb98a4 Preliminary parsing and ASTs for template-ids that refer to function
templates, such as make<int&>. These template-ids are only barely
functional for function calls; much more to come.

llvm-svn: 74563
2009-06-30 22:34:41 +00:00
Douglas Gregor dda7ced32e 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.

llvm-svn: 74540
2009-06-30 17:20:14 +00:00
Douglas Gregor cf0b47d179 During template argument deduction from a function call, allow
deduction from pointer and pointer-to-member types to work even in the
presence of a qualification conversion (C++ [temp.deduct.type]p3
bullet 2). 

llvm-svn: 74354
2009-06-26 23:10:12 +00:00
Anders Carlsson 94ff77a356 More auto work.
llvm-svn: 74339
2009-06-26 22:18:59 +00:00
Anders Carlsson f82bb6b4ed Fix test.
llvm-svn: 74335
2009-06-26 21:54:43 +00:00
Douglas Gregor febe45a727 A little template argument deduction test uncovered an "oops". As part
of template instantiation, we were dropping cv-qualifiers on the
instantiated type in a few places. This change reshuffles the
type-instantiation code a little bit so that there's a single place
where we add qualifiers to the instantiated type, so that we won't end
up with this same bug in the future.

llvm-svn: 74331
2009-06-26 21:40:05 +00:00
Douglas Gregor 705c900d23 Template argument deduction is no longer responsible for checking
non-dependent parameter types. Instead, class template partial
specializations perform a final check of all of the instantiated
arguments. This model is cleaner, and works better for function
templates where the "final check" occurs during overload resolution.

Also, cope with cv-qualifiers when the parameter type was originally a
reference type, so that the deduced argument can be more qualified
than the transformed argument.

llvm-svn: 74323
2009-06-26 20:57:09 +00:00
Anders Carlsson 6bd992d1c3 Can't have arrays of auto.
llvm-svn: 74314
2009-06-26 19:33:28 +00:00
Anders Carlsson 364035d1a8 An auto variable can't appear in its own initializer.
llvm-svn: 74312
2009-06-26 19:16:07 +00:00
Douglas Gregor cceb97559e Improve template argument deduction for reference parameters when
deducing template arguments from a function call. Plus, add a bunch of
tests.

llvm-svn: 74301
2009-06-26 18:27:22 +00:00
Douglas Gregor ad3f2fcf43 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.

llvm-svn: 74213
2009-06-25 22:08:12 +00:00