Commit Graph

88 Commits

Author SHA1 Message Date
Douglas Gregor 25ab25f39d When using a default function argument for a function template (or
member function thereof), perform the template instantiation each time
the default argument is needed. This ensures that
  (1) We get different CXXTemporary objects for each instantiation, and
  (2) Any other instantiations or definitions triggered by the
  instantiation of the default argument expression are guaranteed to
  happen; previously, they might have been suppressed, e.g., because
  they happened in an unevaluated context.

This fixes the majority of PR5810. However, it does not address the
problem where we may have multiple uses of the same CXXTemporary
within an expression when the temporary came from a non-instantiated
default argument expression.

llvm-svn: 92015
2009-12-23 18:19:08 +00:00
Ted Kremenek 49ace5cd62 Fix CXXConstructExpr::getSourceRange() to not include the source ranges of CXXDefaultArgExprs when computing its range (since these expressions have no source range, and using them will make the encompassing range invalid).
llvm-svn: 91984
2009-12-23 04:00:48 +00:00
Douglas Gregor 4f4b186215 When value-initializing a class with no user-defined constructors but
with a non-trivial default constructor, zero-initialize the storage
and then call the default constructor. Fixes PR5800.

llvm-svn: 91548
2009-12-16 18:50:27 +00:00
Douglas Gregor 85dabae6ad Switch the C++ new expression over to InitializationSequence, rather
than using its own partial implementation of initialization. 

Switched CheckInitializerTypes over to
InitializedEntity/InitializationKind, to help move us closer to
InitializationSequence.

Added InitializedEntity::getName() to retrieve the name of the entity,
for diagnostics that care about such things.

Implemented support for default initialization in
InitializationSequence.

Clean up the determination of the "source expressions" for an
initialization sequence in InitializationSequence::Perform.

Taught CXXConstructExpr to store more location information.

llvm-svn: 91492
2009-12-16 01:38:02 +00:00
Anders Carlsson 6e997b2993 ShouldDestroyTemporaries? I don't think so.
llvm-svn: 91450
2009-12-15 20:51:39 +00:00
Sebastian Redl 79eba1ca3b Introduce the notion of literal types, as specified in C++0x.
llvm-svn: 90361
2009-12-03 00:13:20 +00:00
John McCall 2d74de9632 Rework how we support C++ implicit member accesses. If we can resolve an
implicit member access to a specific declaration, go ahead and create
it as a DeclRefExpr or a MemberExpr (with implicit CXXThisExpr base) as
appropriate.  Otherwise, create an UnresolvedMemberExpr or
DependentScopeMemberExpr with a null base expression.

By representing implicit accesses directly in the AST, we get the ability
to correctly delay the decision about whether it's actually an instance
member access or not until resolution is complete.  This permits us
to correctly avoid diagnosing the 'problem' of 'MyType::foo()'
where the relationship to the type isn't really known until instantiation.

llvm-svn: 90266
2009-12-01 22:10:20 +00:00
John McCall 10eae1851d Eliminate the use of OverloadedFunctionDecl in member expressions.
Create a new UnresolvedMemberExpr for these lookups.  Assorted hackery
around qualified member expressions;  this will all go away when we
implement the correct (i.e. extremely delayed) implicit-member semantics.

llvm-svn: 90161
2009-11-30 22:42:35 +00:00
Douglas Gregor 7bab5ff8e7 Eliminate CXXConditionDeclExpr with extreme prejudice.
All statements that involve conditions can now hold on to a separate
condition declaration (a VarDecl), and will use a DeclRefExpr
referring to that VarDecl for the condition expression. ForStmts now
have such a VarDecl (I'd missed those in previous commits).

Also, since this change reworks the Action interface for
if/while/switch/for, use FullExprArg for the full expressions in those
expressions, to ensure that we're emitting

Note that we are (still) not generating the right cleanups for
condition variables in for statements. That will be a follow-on
commit.

llvm-svn: 89817
2009-11-25 00:27:52 +00:00
John McCall e66edc18ae Rip out TemplateIdRefExpr and make UnresolvedLookupExpr and
DependentScopeDeclRefExpr support storing templateids.  Unite the common   
code paths between ActOnDeclarationNameExpr and ActOnTemplateIdExpr.

This gets us to a point where we don't need to store function templates in
the AST using TemplateNames, which is critical to ripping out OverloadedFunction.

Also resolves a few FIXMEs.

llvm-svn: 89785
2009-11-24 19:00:30 +00:00
John McCall 6b51f28e82 Encapsulate "an array of TemplateArgumentLocs and two angle bracket locations" into
a new class.  Use it pervasively throughout Sema.

My fingers hurt.

llvm-svn: 89638
2009-11-23 01:53:49 +00:00
John McCall d14a86427f "Incremental" progress on using expressions, by which I mean totally ripping
into pretty much everything about overload resolution in order to wean
BuildDeclarationNameExpr off LookupResult::getAsSingleDecl().  Replace  
UnresolvedFunctionNameExpr with UnresolvedLookupExpr, which generalizes the
idea of a non-member lookup that we haven't totally resolved yet, whether by
overloading, argument-dependent lookup, or (eventually) the presence of   
a function template in the lookup results.  

Incidentally fixes a problem with argument-dependent lookup where we were 
still performing ADL even when the lookup results contained something from
a block scope.  

Incidentally improves a diagnostic when using an ObjC ivar from a class method.
This just fell out from rewriting BuildDeclarationNameExpr's interaction with
lookup, and I'm too apathetic to break it out.

The only remaining uses of OverloadedFunctionDecl that I know of are in
TemplateName and MemberExpr.

llvm-svn: 89544
2009-11-21 08:51:07 +00:00
John McCall 8cd7813ca3 Draw a brighter line between "unresolved" expressions, where we have done the
appropriate lookup and simply can't resolve the referrent yet, and
"dependent scope" expressions, where we can't do the lookup yet because the
entity we need to look into is a dependent type.

llvm-svn: 89402
2009-11-19 22:55:06 +00:00
Douglas Gregor ef986e8fc3 Improve source-location information for implicitly-generated member call expressions
llvm-svn: 86989
2009-11-12 15:31:47 +00:00
John McCall 0ad166672f Track source information for template arguments and template specialization
types.  Preserve it through template instantiation.  Preserve it through PCH,
although TSTs themselves aren't serializable, so that's pretty much meaningless.

llvm-svn: 85500
2009-10-29 08:12:44 +00:00
Douglas Gregor 5d3507d39c Improve handling of initialization by constructor, by ensuring that
such initializations properly convert constructor arguments and fill
in default arguments where necessary. This also makes the ownership
model more clear.

llvm-svn: 81394
2009-09-09 23:08:42 +00:00
Mike Stump 11289f4280 Remove tabs, and whitespace cleanups.
llvm-svn: 81346
2009-09-09 15:08:12 +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 6d5de59d09 Clean up the CXXConstructExpr constructor, add Arg getters.
llvm-svn: 81178
2009-09-08 01:23:37 +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
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
Eli Friedman c96d4963eb Implement __is_empty. Patch by Sean Hunt.
llvm-svn: 79143
2009-08-15 21:55:26 +00:00
Anders Carlsson c5c57c3b86 Get rid of Stmt::Clone now that we can reference count statements instead.
llvm-svn: 78452
2009-08-08 02:50:17 +00:00
Douglas Gregor e26a285c8f Separate Stmt::Destroy into the entrypoint for destroying a statement
or expression (Destroy) from the virtual function used to actually
destroy a given expression (DoDestroy). 

llvm-svn: 78375
2009-08-07 06:08:38 +00:00
Fariborz Jahanian 800f37262c Support for use of default argument in constructors.
work in progress.

llvm-svn: 78132
2009-08-05 00:26:10 +00:00
Ted Kremenek c23c7e6a51 Change uses of:
Type::getAsReferenceType() -> Type::getAs<ReferenceType>()
  Type::getAsRecordType() -> Type::getAs<RecordType>()
  Type::getAsPointerType() -> Type::getAs<PointerType>()
  Type::getAsBlockPointerType() -> Type::getAs<BlockPointerType>()
  Type::getAsLValueReferenceType() -> Type::getAs<LValueReferenceType>()
  Type::getAsRValueReferenceType() -> Type::getAs<RValueReferenceType>()
  Type::getAsMemberPointerType() -> Type::getAs<MemberPointerType>()
  Type::getAsReferenceType() -> Type::getAs<ReferenceType>()
  Type::getAsTagType() -> Type::getAs<TagType>()
  
And remove Type::getAsReferenceType(), etc.

This change is similar to one I made a couple weeks ago, but that was partly
reverted pending some additional design discussion. With Doug's pending smart
pointer changes for Types, it seemed natural to take this approach.

llvm-svn: 77510
2009-07-29 21:53:49 +00:00
Douglas Gregor 79f83eda84 This patch fixes the implementations of the __has_trivial_destructor
and __has_trivial_constructor builtin pseudo-functions and
additionally implements __has_trivial_copy and __has_trivial_assign,
from John McCall!

llvm-svn: 76916
2009-07-23 23:49:00 +00:00
Ted Kremenek 8a286fbdb9 Per offline discussion with Steve Naroff, add back Type::getAsXXXType() methods
until Doug Gregor's Type smart pointer code lands (or more discussion occurs).
These methods just call the new Type::getAs<XXX> methods, so we still have
reduced implementation redundancy. Having explicit getAsXXXType() methods makes
it easier to set breakpoints in the debugger.

llvm-svn: 76193
2009-07-17 17:50:17 +00:00
Ted Kremenek b825c0ddc5 Replaced Type::getAsLValueReferenceType(), Type::getAsRValueReferenceType(), Type::getAsMemberPointerType(), Type::getAsTagType(), and Type::getAsRecordType() with their Type::getAs<XXX> equivalents.
llvm-svn: 76139
2009-07-17 01:20:38 +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
Anders Carlsson a42ab8f3d5 Handle temporaries in default arguments.
llvm-svn: 73462
2009-06-16 03:37:31 +00:00
Anders Carlsson b3d05d6d11 Improvements to CXXExprWithTemporaries in preparation for fixing a bug with default arguments that have temporaries.
llvm-svn: 72944
2009-06-05 15:38:08 +00:00
Anders Carlsson 73b836bf3d Clean up the newly added C++ AST nodes.
llvm-svn: 72643
2009-05-30 22:38:53 +00:00
Anders Carlsson a29ded9ba8 Stop using CXXTempVarDecl and use CXXTemporary instead.
llvm-svn: 72634
2009-05-30 21:05:25 +00:00
Anders Carlsson 4b2434da54 Remove VarDecl from CXXConstructExpr.
llvm-svn: 72633
2009-05-30 20:56:46 +00:00
Anders Carlsson ffda606612 Small fixes to CXXTemporary and CXXBindTemporaryExpr.
llvm-svn: 72628
2009-05-30 20:34:37 +00:00
Anders Carlsson 993a4b3080 Add a CXXBindTemporaryExpr.
llvm-svn: 72627
2009-05-30 20:03:25 +00:00
Anders Carlsson f337d8c515 Add a CXXTemporary class. Not used yet.
llvm-svn: 72626
2009-05-30 19:54:15 +00:00
Douglas Gregor a8db954f24 Representation of and template instantiation for member
expressions. This change introduces another AST node,
CXXUnresolvedMemberExpr, that captures member references (x->m, x.m)
when the base of the expression (the "x") is type-dependent, and we
therefore cannot resolve the member reference yet.

Note that our parsing of member references for C++ is still quite
poor, e.g., we don't handle x->Base::m or x->operator int.

llvm-svn: 72281
2009-05-22 21:13:27 +00:00
Douglas Gregor e70f108158 Template instantiation for the various kinds of AST nodes that occur
due to C++ type construction of the form T(a1, a2, ..., aN).

llvm-svn: 72183
2009-05-20 21:38:11 +00:00
Douglas Gregor ce934146d0 Introduce a new expression type, CXXUnresolvedConstructExpr, to
describe the construction of a value of a given type using function
syntax, e.g.,
  
  T(a1, a2, ..., aN)

when the type or any of its arguments are type-dependent. In this
case, we don't know what kind of type-construction this will be: it
might construct a temporary of type 'T' (which might be a class or
non-class type) or might perform a conversion to type 'T'. Also,
implement printing of and template instantiation for this new
expression type. Due to the change in Sema::ActOnCXXTypeConstructExpr,
our existing tests cover template instantiation of this new expression
node.

llvm-svn: 72176
2009-05-20 18:46:25 +00:00
Douglas Gregor be81045db7 Template instantiation for call expressions.
llvm-svn: 72081
2009-05-19 00:38:01 +00:00
Sebastian Redl e769ecf8ab Implement instantiation of a few boring, simple expressions. I don't think these are testable yet, though.
llvm-svn: 71953
2009-05-16 18:50:46 +00:00
Sebastian Redl 576fd424df Implement C++0x nullptr.
llvm-svn: 71405
2009-05-10 18:38:11 +00:00
Anders Carlsson aa10d656b5 Get rid of CXXDestroyExpr.
llvm-svn: 70586
2009-05-01 22:21:22 +00:00
Anders Carlsson f58c243830 Rename CXXExprWithCleanup to CXXExprWithTemporaries.
llvm-svn: 70584
2009-05-01 22:18:43 +00:00
Eli Friedman 37e663df63 Silence gcc warnings.
llvm-svn: 70086
2009-04-25 22:20:56 +00:00
Anders Carlsson defc644e06 Add CXXExprWithCleanup
llvm-svn: 70000
2009-04-24 22:47:04 +00:00