Commit Graph

163 Commits

Author SHA1 Message Date
Anders Carlsson ed8d80d72b Separate EK_ArrayOrVectorElement into EK_ArrayElement and EK_VectorElement; arrays and vectors are pretty different beasts in C++. Doug, please review/comment.
llvm-svn: 94279
2010-01-23 04:34:47 +00:00
John McCall ad371258aa Give UnresolvedSet the ability to store access specifiers for each declaration.
Change LookupResult to use UnresolvedSet.  Also extract UnresolvedSet into its
own header and make it templated over an inline capacity.

llvm-svn: 93959
2010-01-20 00:46:10 +00:00
Chandler Carruth 04bdce6407 Fix the CodeGen half of PR5911 by changing reference initialization to
correctly look through arrays to see cv-qualifiers. Also enhances the routine
for doing this to preserve more type sugaring for diagnostics.

llvm-svn: 93252
2010-01-12 20:32:25 +00:00
John McCall ad907777e8 So I was sitting around, trying vainly to think of something to commit, and then
I said to myself, self, why don't you go add a couple of parameters to a method
and then fail to use them, and I thought that sounded like a pretty good idea,
so I did it.

llvm-svn: 93233
2010-01-12 07:18:19 +00:00
John McCall 0d1da2298a Introduce a specific representation for the ambiguous implicit conversion
sequence.  Lots of small relevant changes.  Fixes some serious problems with
ambiguous conversions;  also possibly improves associated diagnostics.

llvm-svn: 93214
2010-01-12 00:44:57 +00:00
John McCall 12f97bc48a Change the printing of OR_Deleted overload results to print all the candidates,
not just the viable ones.  This is reasonable because the most common use of
deleted functions is to exclude some implicit conversion during calls;  users
therefore will want to figure out why some other options were excluded.

Started sorting overload results.  Right now it just sorts by location in the
translation unit (after putting viable functions first), but we can do better than
that.

Changed bool OnlyViable parameter to PrintOverloadCandidates to an enum for better
self-documentation.

llvm-svn: 92990
2010-01-08 04:41:39 +00:00
Douglas Gregor 6da83624e4 Whenever we emit a typo-correction diagnostic, also emit a note
pointing to the declaration that we found that has that name (if it is
unique).

llvm-svn: 92877
2010-01-07 00:17:44 +00:00
Douglas Gregor 03e8bdc07e Move the allocation of designators in DesignatedInitExpr to the
ASTContext. Fixes <rdar://problem/7495428>.

llvm-svn: 92867
2010-01-06 23:17:19 +00:00
Douglas Gregor 4e0299b657 Typo correction for C99 designated field initializers, e.g.,
test/FixIt/typo.c:19:4: error: field designator 'bunds' does not refer to any
      field in type 'struct Window'; did you mean 'bounds'?
  .bunds.
   ^~~~~
   bounds

llvm-svn: 92376
2010-01-01 00:03:05 +00:00
Douglas Gregor bbeb5c391c Switch parameter-passing for calls via function pointers (where we
don't have a FunctionDecl) over to InitializationSequence.

llvm-svn: 91906
2009-12-22 16:09:06 +00:00
Douglas Gregor 1b3039344b Switch InitializedEntity from TypeLoc down to just QualTypes, since we don't use the location information but we did spend a bunch of time building faked-up TypeLocs
llvm-svn: 91905
2009-12-22 15:35:07 +00:00
Douglas Gregor 96596c98fb Switch initialization of parameters in a call over to
InitializationSequence (when a FunctionDecl is present). This required
a few small fixes to initialization sequences:

  - Make sure to use the adjusted parameter type for initialization of
  function parameters.
  - Implement transparent union calling semantics in C

llvm-svn: 91902
2009-12-22 07:24:36 +00:00
Eli Friedman e2808379b8 Zap CheckInitializerTypes.
llvm-svn: 91884
2009-12-22 02:50:30 +00:00
Eli Friedman a553d4ac95 Switch compound literals over to InitializationSequence.
llvm-svn: 91882
2009-12-22 02:35:53 +00:00
Eli Friedman 463e523ad8 Switch file-scope assignment initialization over to InitializationSequence.
llvm-svn: 91881
2009-12-22 02:10:53 +00:00
Douglas Gregor 507eb87f05 Eliminate the ASTContext argument to CXXConstructorDecl::isCopyConstructor, since the context is available in the Decl
llvm-svn: 91862
2009-12-22 00:34:07 +00:00
Douglas Gregor 2bb0765bb4 When filling in value initializations within an initializer list, be
sure to fill in the initialized member of a union when a member was
explicitly designated. Fixes PR5843.

llvm-svn: 91858
2009-12-22 00:05:34 +00:00
Eli Friedman 4afe9a3518 Fix review comment; no visible change.
llvm-svn: 91797
2009-12-20 22:12:03 +00:00
Douglas Gregor 39c778b443 Switch default-initialization of variables of class type (or array thereof) over to InitializationSequence. I could swear that this fixes a PR somewhere, but I couldn't figure out which one
llvm-svn: 91796
2009-12-20 22:01:25 +00:00
Eli Friedman 7827520ce8 Initialization improvements: addition of string initialization and a few
small bug fixes in SemaInit, switch over SemaDecl to use it more often, and
change a bunch of diagnostics which are different with the new initialization
code.

llvm-svn: 91767
2009-12-19 08:11:05 +00:00
Douglas Gregor a4b592a7d5 Switch more of Sema::CheckInitializerTypes over to
InitializationSequence. Specially, switch initialization of a C++
class type (either copy- or direct-initialization). 

Also, make sure that we create an elidable copy-construction when
performing copy initialization of a C++ class variable. Fixes PR5826.

llvm-svn: 91750
2009-12-19 03:01:41 +00:00
Douglas Gregor e1314a64b8 Switch the initialization required by return statements over to the
new InitializationSequence. This fixes some bugs (e.g., PR5808),
changed some diagnostics, and caused more churn than expected. What's
new:

  - InitializationSequence now has a "C conversion sequence" category
    and step kind, which falls back to
  - Changed the diagnostics for returns to always have the result type
    of the function first and the type of the expression second.
    CheckSingleAssignmentConstraints to peform checking in C. 
  - Improved ASTs for initialization of return values. The ASTs now
    capture all of the temporaries we need to create, but
    intentionally do not bind the tempoary that is actually returned,
    so that it won't get destroyed twice.
  - Make sure to perform an (elidable!) copy of the class object that
    is returned from a class.
  - Fix copy elision in CodeGen to properly see through the
    subexpressions that occur with elidable copies.
  - Give "new" its own entity kind; as with return values and thrown
    objects, we don't bind the expression so we don't call a
    destructor for it.

Note that, with this patch, I've broken returning move-only types in
C++0x. We'll fix it later, when we tackle NRVO.

llvm-svn: 91669
2009-12-18 05:02:21 +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 59ae3c8542 In Sema::CheckInitializerTypes, replace a use of CheckReferenceInit with an InitializationSequence
llvm-svn: 91542
2009-12-16 16:54:16 +00:00
Douglas Gregor 723796af7a Eliminate Sema::CheckValueInitialization; its callers now use
InitializationSequence to perform the actual initialization.

Also, introduced the notion of a tree of initialized entities, so that
we can know where an initialization began when dealing with nested
initializations (as occur when performing list initialization). This
will, eventually, be useful for producing better diagnostics when list
initialization fails, because we can show the path from the top-level
object being initialized down to the actual subobject where
initialization failed.

llvm-svn: 91516
2009-12-16 06:35:08 +00:00
Douglas Gregor 7c3bbdfd28 Fix semantic diagnostics that embed English works, from Nicola Gigante!
llvm-svn: 91503
2009-12-16 03:45:30 +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
Douglas Gregor 7dc42e5d4c Implement value initialization in InitializationSequence; untested
WIP, yet again.

llvm-svn: 91368
2009-12-15 00:01:57 +00:00
Douglas Gregor 4f84661c43 Minor cleanups for constructor initialization in InitializationSequence
llvm-svn: 91325
2009-12-14 20:57:13 +00:00
Douglas Gregor 1e7ffa7571 Constructor initialization for InitializationSequence. Untested WIP.
llvm-svn: 91323
2009-12-14 20:49:26 +00:00
Douglas Gregor 540c3b0e50 Implement user-defined conversions in InitializationSequence. WPI that
isn't turned on anyway yet, so it cannot be tested.

llvm-svn: 91294
2009-12-14 17:27:33 +00:00
Chandler Carruth 8abbc657a9 Silence some release build warnings.
llvm-svn: 91234
2009-12-13 01:37:04 +00:00
Jeffrey Yasskin 1615d45daa Un-namespace-qualify llvm_unreachable. It's a macro, so the qualification gave
no extra safety anyway.

llvm-svn: 91207
2009-12-12 05:05:38 +00:00
Eli Friedman ad6c2e5b3a Fix a recent regression from the initialization changes.
llvm-svn: 91097
2009-12-11 02:42:07 +00:00
Douglas Gregor 51e77d5ab0 Move initialization via initializer list over to InitializationSequences.
llvm-svn: 91050
2009-12-10 17:56:55 +00:00
Douglas Gregor 3e1e527826 Reimplement reference initialization (C++ [dcl.init.ref]) using the
new notion of an "initialization sequence", which encapsulates the
computation of the initialization sequence along with diagnostic
information and the capability to turn the computed sequence into an
expression. At present, I've only switched one CheckReferenceInit
callers over to this new mechanism; more will follow.

Aside from (hopefully) being much more true to the standard, the
diagnostics provided by this reference-initialization code are a bit
better than before. Some examples:

p5-var.cpp:54:12: error: non-const lvalue reference to type 'struct
Derived'
      cannot bind to a value of unrelated type 'struct Base'
  Derived &dr2 = b; // expected-error{{non-const lvalue reference to
  ...
           ^     ~
p5-var.cpp:55:9: error: binding of reference to type 'struct Base' to
a value of
      type 'struct Base const' drops qualifiers
  Base &br3 = bc; // expected-error{{drops qualifiers}}
        ^     ~~

p5-var.cpp:57:15: error: ambiguous conversion from derived class
      'struct Diamond' to base class 'struct Base':
    struct Diamond -> struct Derived -> struct Base
    struct Diamond -> struct Derived2 -> struct Base
  Base &br5 = diamond; // expected-error{{ambiguous conversion from
      ...
              ^~~~~~~
p5-var.cpp:59:9: error: non-const lvalue reference to type 'long'
      cannot bind to
      a value of unrelated type 'int'
  long &lr = i; // expected-error{{non-const lvalue reference to type
      ...
        ^    ~

p5-var.cpp:74:9: error: non-const lvalue reference to type 'struct
Base' cannot
      bind to a temporary of type 'struct Base'
  Base &br1 = Base(); // expected-error{{non-const lvalue reference to
  ...
        ^     ~~~~~~

p5-var.cpp:102:9: error: non-const reference cannot bind to bit-field
'i'
  int & ir1 = (ib.i); // expected-error{{non-const reference cannot
  ...
        ^     ~~~~~~
p5-var.cpp:98:7: note: bit-field is declared here
  int i : 17; // expected-note{{bit-field is declared here}}
      ^

llvm-svn: 90992
2009-12-09 23:02:17 +00:00
Chris Lattner 3c7b86f4ee remove some extraneous syntax: sourceloc implicitly converts to sourcerange.
llvm-svn: 90710
2009-12-06 17:36:05 +00:00
Douglas Gregor deebf6efab 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!

llvm-svn: 89407
2009-11-19 23:25:22 +00:00
Douglas Gregor ad2956c25d 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).

llvm-svn: 89366
2009-11-19 18:03:26 +00:00
Douglas Gregor 1b8fe5b716 First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:

  typedef const int CInt;
  typedef CInt Self;

Self.isConstQualified() currently returns false!

Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions: 

  - the "local" version only returns qualifiers on this particular
    QualType instance
  - the "normal" version that will eventually combine qualifiers from this
    QualType instance with the qualifiers on the canonical type to
    produce the full set of qualifiers.

This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
  
  Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()

expressions over to 

  Context.hasSameUnqualifiedType(T1, T2)

llvm-svn: 88969
2009-11-16 21:35:15 +00:00
John McCall c5b8225285 Remove the ConstantArrayType subtypes. This information is preserved in the
TypeLoc records for declarations;  it should not be necessary to represent it
directly in the type system.

Please complain if you were using these classes and feel you can't replicate
previous functionality using the TypeLoc API.

llvm-svn: 84222
2009-10-16 00:14:28 +00:00
Douglas Gregor c809cc2efa Improve diagnostic location information when checking the initialization of a reference
llvm-svn: 82666
2009-09-23 23:04:10 +00:00
John McCall 9dd450bb78 Change all the Type::getAsFoo() methods to specializations of Type::getAs().
Several of the existing methods were identical to their respective
specializations, and so have been removed entirely.  Several more 'leaf'
optimizations were introduced.

The getAsFoo() methods which imposed extra conditions, like
getAsObjCInterfacePointerType(), have been left in place.

llvm-svn: 82501
2009-09-21 23:43:11 +00:00
Fariborz Jahanian 3e6b57e593 Issue good diagnostics when initialization failes due to
ambiguity in type conversion function selection.

llvm-svn: 81898
2009-09-15 19:12:21 +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
Anders Carlsson 5995a3e8fa BuildCXXConstructExpr now takes a MultiExprArg.
llvm-svn: 81160
2009-09-07 22:23:31 +00:00
Anders Carlsson 1b4ebfab2b Pass the ConstructLoc to BuildCXXConstructExpr.
llvm-svn: 81068
2009-09-05 07:40:38 +00:00
Anders Carlsson 20d1332d76 Add an InOverloadResolution flag to TryCopyInitialization.
llvm-svn: 80261
2009-08-27 17:37:39 +00:00
Anders Carlsson 271e3a4d47 Remove more default arguments.
llvm-svn: 80260
2009-08-27 17:30:43 +00:00