Commit Graph

57 Commits

Author SHA1 Message Date
Douglas Gregor 5d1b4e3d1f When we notice that a member function is defined with "= delete" or "=
default", make a note of which is used when creating the
initial declaration. Previously, we would wait until later to handle
default/delete as a definition, but this is too late: when adding the
declaration, we already treated the declaration as "user-provided"
when in fact it was merely "user-declared".

Fixes PR10861 and PR10442, along with a bunch of FIXMEs.

llvm-svn: 144011
2011-11-07 20:56:01 +00:00
Richard Smith aed32b4d8c Simplify RecordDeclCXX::setBases slightly. No functional change.
Add test that a variadic base list which expands to 0 bases doesn't make the
class a non-aggregate. This test passed before the change, too.

llvm-svn: 142411
2011-10-18 20:08:55 +00:00
David Blaikie cc5f8f0d9e Switch to the C++11 warning flags in tests.
Patch by Ahmed Charles!

llvm-svn: 142340
2011-10-18 05:54:07 +00:00
Richard Smith 9ca5c42582 Update all tests other than Driver/std.cpp to use -std=c++11 rather than
-std=c++0x. Patch by Ahmed Charles!

llvm-svn: 141900
2011-10-13 22:29:44 +00:00
Douglas Gregor b06fa540e8 When adding a direct initializer to a declaration, allow the
initializer to update the type of the declaration. For example, this
allows us to determine the size of an incomplete array from its
initializer. Fixes PR10288.

llvm-svn: 141543
2011-10-10 16:05:18 +00:00
Douglas Gregor b0e6c8a350 Don't allow an rvalue reference to bind to the result of a calling a
conversion function whose result type is an lvalue reference. The
initialization code already handled this properly, but overload
resolution was allowing the binding. Fixes PR11003 /
<rdar://problem/10233078>.

llvm-svn: 141137
2011-10-04 23:59:32 +00:00
Daniel Dunbar 58d0af6c5f Basic/Diagnostics: Rewrite DiagnosticIDs::getDiagnosticLevel completely to be straighter line code, use the new DiagnosticMappingInfo flags, and eliminate the odd MAP_WARNING_NO_WERROR and friend mappings.
- This fixes a host of obscure bugs with regards to how warning mapping options composed with one another, and I believe makes the code substantially easier to read and reason about.

llvm-svn: 140770
2011-09-29 01:58:05 +00:00
Richard Smith a528507418 Implement the suggested resolution of WG21 N3307 issue 19: When determining whether a class is an aggregate in C++0x, treat all functions which are neither deleted nor defaulted as user-provided, not just special member functions. The wording of the standard only defines the term "user-provided" for special member functions, but the intent seems to be that any function can be user-provided.
llvm-svn: 139111
2011-09-05 02:13:09 +00:00
Jeffrey Yasskin 924255875e Fix PR10694: Boolean conversions can be from pointers, and those conversions
aren't considered narrowing conversions.

llvm-svn: 138838
2011-08-30 22:25:41 +00:00
Sebastian Redl 22653bac1a Declare and define implicit move constructor and assignment operator.
This makes the code duplication of implicit special member handling even worse,
but the cleanup will have to come later. For now, this works.
Follow-up with tests for explicit defaulting and enabling the __has_feature
flag to come.

llvm-svn: 138821
2011-08-30 19:58:05 +00:00
Jeffrey Yasskin 74231381a3 Print 'int' instead of 'const int' in the narrowing conversion error, since the
qualification of a type doesn't affect whether a conversion is a narrowing
conversion.
This doesn't work in template cases because SubstTemplateTypeParmType gets in
the way.

llvm-svn: 138735
2011-08-29 15:59:37 +00:00
Douglas Gregor 3ec7910e10 Teach reference initialization from the result of a user-defined
conversion to initialize the standard conversion *after* the
user-defined conversion properly. Fixes PR10644.

llvm-svn: 137608
2011-08-15 13:59:46 +00:00
Jeffrey Yasskin 94f8c77931 Conversions to bool count as integer conversions for the purposes of
the C++0x narrowing error.

llvm-svn: 137512
2011-08-12 20:56:43 +00:00
Jeffrey Yasskin a6667816d5 This patch implements as much of the narrowing conversion error specified by
[dcl.init.list] as is possible without generalized initializer lists or full
constant expression support, and adds a c++0x-compat warning in C++98 mode.

The FixIt currently uses a typedef's basename without qualification, which is
likely to be incorrect on some code.  If it's incorrect on too much code, we
should write a function to get the string that refers to a type from a
particular context.

The warning is currently off by default. I'll fix LLVM and clang before turning
it on.

llvm-svn: 136181
2011-07-26 23:20:30 +00:00
Rafael Espindola 699fc4d15c Revert 135177 to fix PR10363.
Revert "For C++11, do more checking of initializer lists up-front, enabling some subset of the final functionality. C just leaves the function early. C++98 runs through the same code path, but has no changed functionality either."

This reverts commit ac420c5053d6aa41d59f782caad9e46e5baaf2c2.

llvm-svn: 135210
2011-07-14 22:58:04 +00:00
Sebastian Redl 9c61809c23 For C++11, do more checking of initializer lists up-front, enabling some subset of the final functionality. C just leaves the function early. C++98 runs through the same code path, but has no changed functionality either.
This is a first baby step towards supporting generalized initializer lists. This also removes an aggregate
test case that was just plain wrong, assuming that non-aggregates couldn't be initialized with initializer lists
in C++11 mode.

llvm-svn: 135177
2011-07-14 19:08:10 +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
Douglas Gregor 9574af6ea2 Teach Sema::ActOnUninitializedDecl() not to try to interpret when one
should use a constructor to default-initialize a
variable. InitializationSequence knows the rules for default
initialization, better. Fixes <rdar://problem/8501008>.

llvm-svn: 131796
2011-05-21 17:52:48 +00:00
Eli Friedman 554eba9c08 PR9669: implement correct checking for [dcl.init.string]p2.
llvm-svn: 129260
2011-04-11 00:23:45 +00:00
Douglas Gregor f143cd5051 Re-instate r123977/r123978, my updates of the reference-binding
implementation used by overload resolution to support rvalue
references. The original commits caused PR9026 and some
hard-to-reproduce self-host breakage.

The only (crucial!) difference between this commit and the previous
commits is that we now properly check the SuppressUserConversions flag
before attempting to perform a second user-defined conversion in
reference binding, breaking the infinite recursion chain of
user-defined conversions.

Rvalue references should be working a bit better now.

llvm-svn: 124121
2011-01-24 16:14:37 +00:00
Rafael Espindola be468d9a2b revert r123977 and r123978 to fix PR9026.
llvm-svn: 124033
2011-01-22 15:32:35 +00:00
Douglas Gregor 95273c3a22 Update the reference-binding implementation used for overload
resolution to match the latest C++0x working paper's semantics. The
implementation now matching up with the reference-binding
implementation used for initialization.

llvm-svn: 123977
2011-01-21 16:36:05 +00:00
Douglas Gregor 9b175e0512 Add more reference-binding examples from the C++0x working paper, all of which seem to be working fine
llvm-svn: 123955
2011-01-21 01:11:43 +00:00
Douglas Gregor 24f2e8ec00 More work to bring reference binding up to the latest C++0x
specification. In particular, an rvalue reference can bind to an
initializer expression that is an lvalue if the referent type and the
initializer expression type are not reference-related. This is a newer
formulation to the previous "rvalue references can never bind to
lvalues" rule.

llvm-svn: 123952
2011-01-21 00:52:42 +00:00
Douglas Gregor d412fe598b When performing reference binding via a conversion function, perform
type checking based on the actual reference type we're trying to bind
the result to, rather than stripping the reference.

llvm-svn: 123950
2011-01-21 00:27:08 +00:00
Douglas Gregor 56d7eae857 More tests for reference binding in the presence of rvalue
references. Note that we're currently failing reference binding to a
function lvalue.

llvm-svn: 123920
2011-01-20 17:04:36 +00:00
Douglas Gregor 92e460e909 Start refactoring reference binding to more closely match the C++0x
working paper's structure. The only functional change here is that we
now handling binding to array rvalues, which we would previously reject.

llvm-svn: 123918
2011-01-20 16:44:54 +00:00
Douglas Gregor 7a2a116bab Add some tests for reference-collapsing and referencing binding
involving rvalue references, to start scoping out what is and what
isn't implemented. In the process, tweak some standards citations,
type desugaring, and teach the tentative parser about && in
ptr-operator.

llvm-svn: 123913
2011-01-20 16:08:06 +00:00
John McCall 7decc9e4ea Calculate the value kind of an expression when it's created and
store it on the expression node.  Also store an "object kind",
which distinguishes ordinary "addressed" l-values (like
variable references and pointer dereferences) and bitfield,
@property, and vector-component l-values.

Currently we're not using these for much, but I aim to switch
pretty much everything calculating l-valueness over to them.
For now they shouldn't necessarily be trusted.

llvm-svn: 119685
2010-11-18 06:31:45 +00:00
Douglas Gregor cbd0710a12 When performing initialization of a copy of a temporary object, use
direct-initialization (rather than copy-initialization) to initialize
the temporary, allowing explicit constructors. Fixes PR8342.

llvm-svn: 118880
2010-11-12 03:34:06 +00:00
Argyrios Kyrtzidis dfbdfbba8f In Sema's TryRefInitWithConversionFunction, suppress user conversions for the overload candidates.
Fixes an infinite recursion in overload resolution for rdar://8499524.
Many thanks to Doug!

llvm-svn: 115588
2010-10-05 03:05:30 +00:00
Chris Lattner 24b89469ac 'const std::type_info*' instead of 'std::type_info const*'
llvm-svn: 113092
2010-09-05 00:17:29 +00:00
Chris Lattner 53fa04909c make clang print types as "const int *" instead of "int const*",
which is should have done from the beginning.  As usual, the most
fun with this sort of change is updating all the testcases.

llvm-svn: 113090
2010-09-05 00:04:01 +00:00
Chandler Carruth fc0e2a03fa Fix a regression that allowed clearly ill formed code. The diagnostic is still
terrible, FIXME left to do a proper job of diagnosing this.

llvm-svn: 112581
2010-08-31 05:42:40 +00:00
Jeffrey Yasskin caa710dfd2 PR7245: Make binding a reference to a temporary without a usable copy
constructor into an extension warning into the error that C++98 requires.

llvm-svn: 105529
2010-06-07 15:58:05 +00:00
Jeffrey Yasskin c9b9bdcc20 There is no dcl.init.ref p16. This test deals with p5.
llvm-svn: 105351
2010-06-02 22:01:22 +00:00
Anders Carlsson a70cff624e Actually produce base paths for CastExprs of kind CK_DerivedToBase.
llvm-svn: 102259
2010-04-24 19:06:50 +00:00
Douglas Gregor 30b5277a0a When checking the copy constructor for the optional copy during a
reference binding to an rvalue of reference-compatible type, check
parameters after the first for complete parameter types and build any
required default function arguments. We're effectively simulating the
type-checking for a call without building the call itself.

llvm-svn: 101705
2010-04-18 07:57:34 +00:00
Douglas Gregor c9cd64eee3 In C++98/03, when binding a reference to an rvalue of
reference-compatible type, the implementation is permitted to make a
copy of the rvalue (or many such copies, even). However, even though
we don't make that copy, we are required to check for the presence of
a suitable copy constructor. With this change, we do.

Note that in C++0x we are not allowed to make these copies, so we test
both dialects separately.

Also note the FIXME in one of the C++03 tests, where we are not
instantiating default function arguments for the copy constructor we
pick (but do not call). The fix is obvious; eliminating the infinite
recursion it causes is not. Will address that next.

llvm-svn: 101704
2010-04-18 07:40:54 +00:00
Douglas Gregor 538be4622c During referencing binding, only consider conversion functions for
direct reference binding when the source and target types are not
reference-related. Fixes PR6066.

llvm-svn: 101132
2010-04-13 15:07:45 +00:00
John McCall 85f9055955 When pretty-printing tag types, only print the tag if we're in C (and
therefore not creating ElaboratedTypes, which are still pretty-printed
with the written tag).

Most of these testcase changes were done by script, so don't feel too
sorry for my fingers.

llvm-svn: 98149
2010-03-10 11:27:22 +00:00
Douglas Gregor 589973b097 In C++98/03, an uninitialized variable that has POD class type will be
uninitialized. This seems not to be the case in C++0x, where we still
call the (trivial) default constructor for a POD class
(!). Previously, we had implemented only the C++0x rules; now we
implement both. Fixes PR6536.

llvm-svn: 97928
2010-03-08 02:45:10 +00:00
Douglas Gregor e6d276a559 Commit Eli's fix for implicit conversions to array type. Fixes PR6264.
llvm-svn: 97202
2010-02-26 01:17:27 +00:00
Douglas Gregor e6565625f4 Migrate the mish-mash of declaration checks in
Sema::ActOnUninitializedDecl over to InitializationSequence (with
default initialization), eliminating redundancy. More importantly, we
now check that a const definition in C++ has an initilizer, which was
an #if 0'd code for many, many months. A few other tweaks were needed
to get everything working again:

  - Fix all of the places in the testsuite where we defined const
    objects without initializers (now that we diagnose this issue)
  - Teach instantiation of static data members to find the previous
    declaration, so that we build proper redeclaration
    chains. Previously, we had the redeclaration chain but built it
    too late to be useful, because...
  - Teach instantiation of static data member definitions not to try
    to check an initializer if a previous declaration already had an
    initializer. This makes sure that we don't complain about static
    const data members with in-class initializers and out-of-line
    definitions.
  - Move all of the incomplete-type checking logic out of
    Sema::FinalizeDeclaratorGroup; it makes more sense in
    ActOnUnitializedDecl.

There may still be a few places where we can improve these
diagnostics. I'll address that as a separate commit.

llvm-svn: 95657
2010-02-09 07:26:29 +00:00
Douglas Gregor 7ae2d7758f Rework base and member initialization in constructors, with several
(necessarily simultaneous) changes:

  - CXXBaseOrMemberInitializer now contains only a single initializer
    rather than a set of initialiation arguments + a constructor. The
    single initializer covers all aspects of initialization, including
    constructor calls as necessary but also cleanup of temporaries
    created by the initializer (which we never handled
    before!).

  - Rework + simplify code generation for CXXBaseOrMemberInitializers,
    since we can now just emit the initializer as an initializer.

  - Switched base and member initialization over to the new
    initialization code (InitializationSequence), so that it

  - Improved diagnostics for the new initialization code when
    initializing bases and members, to match the diagnostics produced
    by the previous (special-purpose) code.

  - Simplify the representation of type-checked constructor initializers in
    templates; instead of keeping the fully-type-checked AST, which is
    rather hard to undo at template instantiation time, throw away the
    type-checked AST and store the raw expressions in the AST. This
    simplifies instantiation, but loses a little but of information in
    the AST.

  - When type-checking implicit base or member initializers within a
    dependent context, don't add the generated initializers into the
    AST, because they'll look like they were explicit.

  - Record in CXXConstructExpr when the constructor call is to
  initialize a base class, so that CodeGen does not have to infer it
  from context. This ensures that we call the right kind of
  constructor.

There are also a few "opportunity" fixes here that were needed to not
regress, for example:

  - Diagnose default-initialization of a const-qualified class that
    does not have a user-declared default constructor. We had this
    diagnostic specifically for bases and members, but missed it for
    variables. That's fixed now.

  - When defining the implicit constructors, destructor, and
    copy-assignment operator, set the CurContext to that constructor
    when we're defining the body.

llvm-svn: 94952
2010-01-31 09:12:51 +00:00
Douglas Gregor aa6050b0e2 PR5909 had a test case for binding of const, non-volatile references
to bitfields. Add it here.

llvm-svn: 94832
2010-01-29 19:42:41 +00:00
Douglas Gregor d1e08648c6 Fix reference-binding when we have a reference to const volatile type;
previously, we were allowing this to bind to a temporary. Now, we
don't; add test-cases and improve diagnostics.

llvm-svn: 94831
2010-01-29 19:39:15 +00:00
John McCall e1ac8d1742 Improve the reporting of non-viable overload candidates by noting the reason
why the candidate is non-viable.  There's a lot we can do to improve this, but
it's a good start.  Further improvements should probably be integrated with the
bad-initialization reporting routines.

llvm-svn: 93277
2010-01-13 00:25:19 +00:00
John McCall fd0b2f8fe4 Improve the diagnostics used to report implicitly-generated class members
as parts of overload sets.  Also, refer to constructors as 'constructors'
rather than functions.

Adjust a lot of tests.

llvm-svn: 92832
2010-01-06 09:43:14 +00:00
Douglas Gregor 5103effb1d A CXXExprWithTemporaries expression is an lvalue if its subexpression
is an lvalue. Fixes PR5787.

llvm-svn: 91765
2009-12-19 07:07:47 +00:00