Commit Graph

1013 Commits

Author SHA1 Message Date
John McCall 1b1a1dbbe7 When synthesizing implicit copy/move constructors and copy/move assignment
operators, don't make an initializer or sub-operation for zero-width
bitfields.

llvm-svn: 133221
2011-06-17 00:18:42 +00:00
John McCall 31168b077c Automatic Reference Counting.
Language-design credit goes to a lot of people, but I particularly want
to single out Blaine Garst and Patrick Beard for their contributions.

Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself,
in no particular order.

llvm-svn: 133103
2011-06-15 23:02:42 +00:00
Richard Smith 938f40b5aa Implement support for C++11 in-class initialization of non-static data members.
llvm-svn: 132878
2011-06-11 17:19:42 +00:00
Alexis Hunt b1b368f36d This change is breaking selfhost. Revert it until I have more time
to study it.

llvm-svn: 132843
2011-06-10 12:07:09 +00:00
Alexis Hunt ff0ff6549d Implement caching of copy assignment operator lookup.
I believe, upon, careful review, that this code causes us to incorrectly
handle exception specifications of copy assignment operators in C++03
mode. However, we currently do not seem to properly implement the subtle
distinction between copying of members and bases made by implicit copy
constructors and assignment operators in C++03 - namely that they are
limited in their overload selection - in all cases. As such, I feel that
committing this code is correct pending a careful review of our
implementation of these semantics.

llvm-svn: 132841
2011-06-10 09:24:41 +00:00
Alexis Hunt 899bd447cf Implement caching for copy constructors in similar situations.
llvm-svn: 132835
2011-06-10 04:44:37 +00:00
Alexis Hunt eef8ee0c8d Implement caching of default constructors on the resolution table. This
isn't yet used for the less controlled environments of initialization.

Also a few random text fixups.

llvm-svn: 132833
2011-06-10 03:50:41 +00:00
Sebastian Redl c7ca587512 Remove all references to InitializationSequence::FailedSequence from outside SemaInit.cpp. Replace them with the boolean conversion or the new Failed() function. This is a first step towards removing InitializationSequence::SequenceKind. No functionality change.
llvm-svn: 132664
2011-06-05 12:23:28 +00:00
Alexis Hunt d051b87160 Implement a new warning for when adding a default argument to a method
makes it into a special member function. This is very bad and can lead
to all sorts of nastiness including implicit member functions violating
the One Definition Rule. This should probably be made ill-formed in a
later version of the standard, but for now we'll just warn.

llvm-svn: 132104
2011-05-26 01:26:05 +00:00
Alexis Hunt 119c10ef23 Update our diagnostics to properly account for move operations.
llvm-svn: 132096
2011-05-25 23:16:36 +00:00
Alexis Hunt fcaeae4929 Implement a little bit of cleanup and a lot more of the base work
behind implicit moves. We now correctly identify move constructors and
assignment operators and update bits on the record correctly. Generation
of implicit moves (declarations or definitions) is not yet supported.

llvm-svn: 132080
2011-05-25 20:50:04 +00:00
Alexis Hunt 61ae8d395e Implement explicit specialization of explicitly-defaulted constructors.
The general out-of-line case (including explicit instantiation mostly
works except that the definition is being lost somewhere between the AST
and CodeGen, so the definition is never emitted.

llvm-svn: 131933
2011-05-23 23:14:04 +00:00
Alexis Hunt 1fb4e76218 Correctly propagate defaultedness across template instantiation. This
fixes PR9965, but we're not out of the water yet, as we do not
successfully handle out-of-line definitions, due to my utter
misunderstanding of how we manage templates.

llvm-svn: 131920
2011-05-23 21:07:59 +00:00
Francois Pichet efb1af9ae8 Emulate a MSVC bug where if during an using declaration name lookup, the declaration found is unaccessible (private) and that declaration was bring into scope via another using declaration whose target declaration is accessible (public) then no error is generated.
Example:
class A { public: int f();  };
class B : public A { private: using A::f; };
class C : public B { private: using B::f; };

Here, B::f is private so this should fail in Standard C++, but because B::f refers to A::f which is public MSVC accepts it.

This fixes 1 error when parsing MFC code with clang.

llvm-svn: 131896
2011-05-23 03:43:44 +00:00
Alexis Hunt a671bca618 Add a missing case for default constructor deletion.
This case is tested by the fact that the modified test produces
significatly worse diagnostics. That's on the list.

llvm-svn: 131759
2011-05-20 21:43:47 +00:00
Douglas Gregor a912197fff Downgrade the error about re-opening an inline namespace as non-inline
to a warning, since apparently libstdc++'s debug mode does this (and
we can recover safely). Add a Fix-It to insert the "inline", just for kicks.

llvm-svn: 131732
2011-05-20 15:48:31 +00:00
Sebastian Redl 623ea82a6b Reapply r121528, fixing PR9941 by delaying the exception specification check for destructors until the class is complete and destructors have been adjusted.
llvm-svn: 131632
2011-05-19 05:13:44 +00:00
Alexis Hunt 1647354ec9 After consultation with doug, revert r131515.
llvm-svn: 131574
2011-05-18 20:57:13 +00:00
Alexis Hunt d0cdd1fab1 Revert r121528 as it breaks a simple testcase, which leads to, among
other things, libcxx not building.

llvm-svn: 131573
2011-05-18 20:57:11 +00:00
Sebastian Redl b900f04ccc Implement implicit exception specifications of destructors.
llvm-svn: 131528
2011-05-18 05:20:56 +00:00
Alexis Hunt e77a28f7e1 Implement an additional fix for infinite recursion of deleted special
member functions by making sure that they're on the record before
checking for deletion.

Also make sure source locations are valid to avoid crashes.

Unfortunately, the declare-all-implicit-members approach is still
required in order to ensure that dependency loops do not result in
incorrectly deleting functions (since they are to be deleted at the
declaration point per the standard).

Fixes PR9917

llvm-svn: 131520
2011-05-18 03:41:58 +00:00
Alexis Hunt 2430a6fb91 Force declaration of implicit members in C++0x mode.
I hear at least one person crying out in anguish, but it's unfortunately
necessary to avoid infinite loops with mutually dependent constructors
trying to call each other and determine if they are deleted.

It might be possible to go back to the old behavior if we can implement
part-of-file lookups efficiently, or if a solution is discovered by
which we can safely detect and avoid infinite recusion.

llvm-svn: 131515
2011-05-18 01:06:45 +00:00
Alexis Hunt 604aeb3849 Fix some minor bugs and add a lot more test cases for defaulted
constructors, including two more FIXMEs (one of which I don't actually
understand).

llvm-svn: 131487
2011-05-17 20:44:43 +00:00
Alexis Hunt 8b4551844c Implement some tests for defaulted constructors. To do this I had to
suppress an error we were previously emitting on valid union code.

llvm-svn: 131440
2011-05-17 00:19:05 +00:00
Alexis Hunt c9a5573ef1 What I hope to be an implementation of defaulted copy assignment
operators.

llvm-svn: 131338
2011-05-14 05:23:28 +00:00
Alexis Hunt b2f2780a16 More progress towards defaulted copy assignment
llvm-svn: 131337
2011-05-14 05:23:24 +00:00
Alexis Hunt 119f365d31 Start implementing defaulted copy assignment
llvm-svn: 131336
2011-05-14 05:23:20 +00:00
Alexis Hunt b5b14c8b8f Fix copy constructor deletion detection with array types.
This fixes PR9910

llvm-svn: 131309
2011-05-13 21:10:11 +00:00
Alexis Hunt 913820daf0 Defaulting copy constructors now works reasonably well.
One more special member to go

llvm-svn: 131287
2011-05-13 06:10:58 +00:00
Alexis Hunt 1f69a02fb9 Implement defaulting of destructors.
llvm-svn: 131260
2011-05-12 22:46:29 +00:00
Alexis Hunt f9172946be Hrm
llvm-svn: 131259
2011-05-12 22:46:25 +00:00
Alexis Hunt 5a7fa250ab Properly parse the 'default' and 'delete' keywords.
They are actually grammatically considered definitions and parsed
accordingly.

This fixes the outstanding bugs regarding defaulting functions after
their declarations.

We now really nicely diagnose the following construct (try it!)

int foo() = delete, bar;

Still todo: Defaulted functions other than default constructors
            Test cases (including for the above construct)

llvm-svn: 131228
2011-05-12 06:15:49 +00:00
Alexis Hunt f92197cf96 Make it so that we actually generate definitions for explicitly
defaulted default constructors.

As it happens, making sure that we handle out-of-line defaulted
functions properly will involved making sure that we actually parse them
correctly, so that's coming after.

llvm-svn: 131224
2011-05-12 03:51:51 +00:00
Alexis Hunt b315302bf9 Implement deletion of explicitly defaulted default constructors.
We still don't parse out-of-line defaults correctly, which is needed to
get the full effect out of this patch.

llvm-svn: 131223
2011-05-12 03:51:48 +00:00
Alexis Hunt 466627ca2e Commit some missing changes to the previous patch.
This means we get C++0x jump-across-intializer semantics correct.

llvm-svn: 131204
2011-05-11 22:50:12 +00:00
Alexis Hunt ea6f0320f0 Implement implicit deletion of default constructors.
Yes, I'm aware that the diagnostics are awful.

Tests to follow.

llvm-svn: 131203
2011-05-11 22:34:38 +00:00
Alexis Hunt 80f00ff95d Re-do R131114 without breaking code.
I've edited one diagnostic which would print "copy constructor" for copy
constructors and "constructor" for any other constructor. If anyone is
extremely enamored with this, it can be reinstated with a simple boolean
flag rather than calling getSpecialMember, which is inappropriate.

llvm-svn: 131143
2011-05-10 19:08:14 +00:00
Douglas Gregor 972fe534ed Reimplement Sema::MatchTemplateParametersToScopeSpecifier() based on
the semantic context referenced by the nested-name-specifier rather
than the syntactic form of the nested-name-specifier. The previous
incarnation was based on my complete misunderstanding of C++
[temp.expl.spec]. The latest C++0x working draft clarifies the
requirements here, and this rewrite is intended to follow that.

Along the way, improve source location information in the
diagnostics. For example, if we report that a specific type needs or
doesn't need a 'template<>' header, we dig out that type in the
nested-name-specifier and highlight its range.

Fixes: PR5907, PR9421, PR8277, PR8708, PR9482, PR9668, PR9877, and
<rdar://problem/9135379>.

llvm-svn: 131138
2011-05-10 18:27:06 +00:00
Rafael Espindola 5fe6d35770 Revert 131114. This fixes PR9884.
llvm-svn: 131126
2011-05-10 14:12:22 +00:00
Alexis Hunt 6d5b96c6b3 Further implement defaulting constructors.
Focus is on default constructors for the time being. Currently the
exception specification and prototype are processed correctly. Codegen
might work but in all likelihood doesn't.

Note that due to an error, out-of-line defaulting of member functions is
currently impossible. It will continue to that until I muster up the
courage to admit that I secretly pray to epimetheus and that I need to
rework the way default gets from Parse -> Sema.

llvm-svn: 131115
2011-05-10 00:49:42 +00:00
Alexis Hunt be3f9ecd18 The last of the trivial constructor changes, make CXXSpecialMember
reflect our new, more accurate AST.

llvm-svn: 131114
2011-05-10 00:41:46 +00:00
Alexis Hunt 88c75c311f Clean up trivial default constructors now.
hasTrivialDefaultConstructor() really really means it now.

Also implement a fun standards bug regarding aggregates. Doug, if you'd
like, I can un-implement that bug if you think it is truly a defect.

The bug is that non-special-member constructors are never considered
user-provided, so the following is an aggregate:

struct foo {
  foo(int);
};

It's kind of bad, but the solution isn't obvious - should

struct foo {
  foo (int) = delete;
};

be an aggregate or not?

Lastly, add a missing initialization to FunctionDecl.

llvm-svn: 131101
2011-05-09 21:45:35 +00:00
Alexis Hunt f479f1b7e4 Rename "hasTrivialConstructor" to "hasTrivialDefaultConstructor" and
modify the semantics slightly to accomodate default constructors (I
hope).

llvm-svn: 131087
2011-05-09 18:22:59 +00:00
Douglas Gregor b578fbe0f2 When checking for a prior declaration of the name of a namespace, skip
any names that aren't in the appropriate identifier namespaces. Fixes
an embarrassing bug where we give a redefinition error due to an
Objective-C category (<rdar://problem/9388207>).

llvm-svn: 131036
2011-05-06 23:28:47 +00:00
Alexis Hunt 83dc3e89c3 Per Richard's suggestion, rename DefLoc to DefaultLoc where it appears.
llvm-svn: 131018
2011-05-06 21:24:28 +00:00
Alexis Hunt 4a8ea1092a Modify some deleted function methods to better reflect reality:
- New isDefined() function checks for deletedness
 - isThisDeclarationADefinition checks for deletedness
 - New doesThisDeclarationHaveABody() does what
   isThisDeclarationADefinition() used to do
 - The IsDeleted bit is not propagated across redeclarations
 - isDeleted() now checks the canoncial declaration
 - New isDeletedAsWritten() does what it says on the tin.
 - isUserProvided() now correct (thanks Richard!)

This fixes the bug that we weren't catching

void foo() = delete;
void foo() {}

as being a redefinition.

llvm-svn: 131013
2011-05-06 20:44:56 +00:00
Alexis Hunt 5dafebc89f Do defaulted constructors properly.
Explictly defaultedness is correctly reflected on the AST, but there are
no changes to how that affects the definition of functions or much else
really.

llvm-svn: 130974
2011-05-06 01:42:00 +00:00
Alexis Hunt 58dad7d978 Revert r130912 in order to approach defaulted functions from the other
direction and not introduce things in the wrong place three different
times.

llvm-svn: 130968
2011-05-06 00:11:07 +00:00
Richard Smith 3f1b5d077b Implement support for C++0x alias templates.
llvm-svn: 130953
2011-05-05 21:57:07 +00:00
Alexis Hunt 1adeff92bc Implement some framework for defaulted constructors.
There's some unused stuff for now.

llvm-svn: 130912
2011-05-05 03:36:28 +00:00