Commit Graph

7933 Commits

Author SHA1 Message Date
Sebastian Redl 2b80af4949 Don't route explicit construction via list-initialization through the functional cast code path. It sometimes does the wrong thing, produces horrible error messages, and is just unnecessary.
llvm-svn: 150408
2012-02-13 19:55:43 +00:00
Douglas Gregor 54fcea6e16 Keep track of the set of array index variables we use when we
synthesize a by-copy captured array in a lambda. This information will
be needed by IR generation.

llvm-svn: 150396
2012-02-13 16:35:30 +00:00
Douglas Gregor c8a734938b Move the storage of lambda captures and capture initializers from
LambdaExpr over to the CXXRecordDecl. This allows us to eliminate the
back-link from the closure type to the LambdaExpr, which will simplify
and lazify AST deserialization.

llvm-svn: 150393
2012-02-13 15:44:47 +00:00
Richard Smith 3607ffee5c Update constexpr implementation to match CWG's chosen approach for core issues
1358, 1360, 1452 and 1453.
 - Instantiations of constexpr functions are always constexpr. This removes the
   need for separate declaration/definition checking, which is now gone.
 - This makes it possible for a constexpr function to be virtual, if they are
   only dependently virtual. Virtual calls to such functions are not constant
   expressions.
 - Likewise, it's now possible for a literal type to have virtual base classes.
   A constexpr constructor for such a type cannot actually produce a constant
   expression, though, so add a special-case diagnostic for a constructor call
   to such a type rather than trying to evaluate it.
 - Classes with trivial default constructors (for which value initialization can
   produce a fully-initialized value) are considered literal types.
 - Classes with volatile members are not literal types.
 - constexpr constructors can be members of non-literal types. We do not yet use
   static initialization for global objects constructed in this way.

llvm-svn: 150359
2012-02-13 03:54:03 +00:00
Douglas Gregor e096a35518 Implement the standard decltype() semantics described in C++11
[dcl.type.simple]p4, which treats all xvalues as returning T&&. We had
previously implemented a pre-standard variant of decltype() that
doesn't cope with, e.g., static_ast<T&&>(e) very well.

llvm-svn: 150348
2012-02-12 18:57:57 +00:00
Douglas Gregor 81495f341d Within the body of a lambda expression, decltype((x)) for an
id-expression 'x' will compute the type based on the assumption that
'x' will be captured, even if it isn't captured, per C++11
[expr.prim.lambda]p18. There are two related refactors that go into
implementing this:

  1) Split out the check that determines whether we should capture a
  particular variable reference, along with the computation of the
  type of the field, from the actual act of capturing the
  variable. 
  2) Always compute the result of decltype() within Sema, rather than
  AST, because the decltype() computation is now context-sensitive.

llvm-svn: 150347
2012-02-12 18:42:33 +00:00
Sebastian Redl d74dd49065 Proper initializer list support for new expressions and type construct expressions. Array new still missing.
llvm-svn: 150346
2012-02-12 18:41:05 +00:00
Douglas Gregor 1a22d2889b Lambdas have a deleted default constructor and a deleted copy
assignment operator, per C++ [expr.prim.lambda]p19. Make it so.

llvm-svn: 150345
2012-02-12 17:34:23 +00:00
Sebastian Redl 0501c63609 Change the way we store initialization kinds so that all direct inits can distinguish between list and parens form. This allows us to correctly diagnose the last test cases from litb.
llvm-svn: 150343
2012-02-12 16:37:36 +00:00
Sebastian Redl 5a41f68fe2 Employ DirectList initialized entities to properly sort through some initialization edge cases.
llvm-svn: 150342
2012-02-12 16:37:24 +00:00
Sebastian Redl a935179ab7 Represent C++ direct initializers as ParenListExprs before semantic analysis
instead of having a special-purpose function.

- ActOnCXXDirectInitializer, which was mostly duplication of
  AddInitializerToDecl (leading e.g. to PR10620, which Eli fixed a few days
  ago), is dropped completely.
- MultiInitializer, which was an ugly hack I added, is dropped again.
- We now have the infrastructure in place to distinguish between
  int x = {1};
  int x({1});
  int x{1};
-- VarDecl now has getInitStyle(), which indicates which of the above was used.
-- CXXConstructExpr now has a flag to indicate that it represents list-
   initialization, although this is not yet used.
- InstantiateInitializer was renamed to SubstInitializer and simplified.
- ActOnParenOrParenListExpr has been replaced by ActOnParenListExpr, which
  always produces a ParenListExpr. Placed that so far failed to convert that
  back to a ParenExpr containing comma operators have been fixed. I'm pretty
  sure I could have made a crashing test case before this.

The end result is a (I hope) considerably cleaner design of initializers.
More importantly, the fact that I can now distinguish between the various
initialization kinds means that I can get the tricky generalized initializer
test cases Johannes Schaub supplied to work. (This is not yet done.)

This commit passed self-host, with the resulting compiler passing the tests. I
hope it doesn't break more complicated code. It's a pretty big change, but one
that I feel is necessary.

llvm-svn: 150318
2012-02-11 23:51:47 +00:00
Sebastian Redl 82ace98d55 Fix parsing new expressions using init lists. Probably still do the wrong thing in cases involving array new.
Show that many cases using initializer list constructors work, in that they parse and pass semantic analysis.

llvm-svn: 150316
2012-02-11 23:51:08 +00:00
Richard Smith b24f06780c Implement core issue 5: a temporary created for copy-initialization has a
cv-unqualified type. This is essential in order to allow move-only objects of
const-qualified types to be copy-initialized via a converting constructor.

llvm-svn: 150309
2012-02-11 19:22:50 +00:00
Richard Smith 4c7b490d19 Make sure to try instantiating a templated type which is used in an _Atomic
before complaining that it's incomplete.

llvm-svn: 150308
2012-02-11 18:03:45 +00:00
Eli Friedman c9751069f5 Make sure Sema creates a field for 'this' captures. (Doug, please double-check that this is correct.)
llvm-svn: 150292
2012-02-11 02:51:16 +00:00
Argyrios Kyrtzidis e378948c8a For class template implicit instantiation, also update its location to point
to the pattern template that it came from, otherwise we had this situation:

template <typename T1, typename T2>
struct S {
};

template <typename T>
struct S<T, int> {
};

void f() {
  S<int, int> s; // location of declaration "S<int, int>" was of "S<T1, T2>" not "S<T, int>"
}

llvm-svn: 150290
2012-02-11 01:59:57 +00:00
Douglas Gregor f0d495100c Implement C++11 [expr.lambda.prim]p13, which prohibits lambdas in
default arguments if in fact those lambdas capture any entity.

llvm-svn: 150282
2012-02-10 23:30:22 +00:00
David Blaikie 59fe3f89cb Support all null pointer literals in format strings.
llvm-svn: 150276
2012-02-10 21:07:25 +00:00
Argyrios Kyrtzidis e5dc5b31f2 [libclang] Indexing API: Fully index implict template instantiations.
llvm-svn: 150267
2012-02-10 20:10:44 +00:00
Ted Kremenek dde2adec89 Enhance checking for null format string literal to take into account __null. Fixes <rdar://problem/8269537>.
llvm-svn: 150260
2012-02-10 19:13:51 +00:00
Douglas Gregor a1bffa26ca Allow implicit capture of 'this' in a lambda even when the capture
default is '=', and reword the warning about explicitly capturing
'this' in such lambdas to indicate that only explicit capture is
banned. 

Introduce Fix-Its for this and other "save the programmer from
themself" rules regarding what can be explicitly captured and what
must be implicitly captured.

llvm-svn: 150256
2012-02-10 17:46:20 +00:00
Douglas Gregor 01db64f0ac Add test from [expr.prim.lambda]p12, which deals with odr-use and
nested captures. We currently don't get odr-use correct in array
bounds, so that bit is commented out while we sort out what we need to
do.

llvm-svn: 150255
2012-02-10 16:48:36 +00:00
Douglas Gregor 04bbab586b Don't introduce a lambda's operator() into the class until after we
have finished parsing the body, so that name lookup will never find
anything within the closure type. Then, add this operator() and the
conversion function (if available) before completing the class.

llvm-svn: 150252
2012-02-10 16:13:20 +00:00
Richard Smith 63168c7533 PR11684, core issue 1417:
o Correct the handling of the restrictions on usage of cv-qualified and
  ref-qualified function types.
o Fix a bug where such types were rejected in template type parameter default
  arguments, due to such arguments not being treated as a template type arg
  context.
o Remove the ExtWarn for usage of such types as template arguments; that was
  a standard defect, not a GCC extension.
o Improve the wording and unify the code for diagnosing cv-qualifiers with the
  code for diagnosing ref-qualifiers.

llvm-svn: 150244
2012-02-10 11:05:11 +00:00
Richard Smith 5e580292ac Track whether a function type has a trailing return type as type sugar. Use this
to pretty-print such function types better, and to fix a case where we were not
instantiating templates in lexical order. In passing, move the Variadic bit from
Type's bitfields to FunctionProtoType to get the Type bitfields down to 32 bits.
Also ensure that we always substitute the return type of a function when
substituting explicitly-specified arguments, since that can cause us to bail
out with a SFINAE error before we hit a hard error in parameter substitution.

llvm-svn: 150241
2012-02-10 09:58:53 +00:00
Douglas Gregor f02455e5ee Add various tests for captures and the reaching scope of the lambda
expression. Implement C++11 [expr.prim.lambda]p12's requirement that
capturing a variable will odr-use it.

llvm-svn: 150237
2012-02-10 09:26:04 +00:00
Douglas Gregor 12695101ec Implement the conversion to a function pointer for lambda expressions,
per C++ [expr.prim.lambda]p6.

llvm-svn: 150236
2012-02-10 08:36:38 +00:00
Douglas Gregor 9c702207e5 Extend CXXRecordDecl with a function that determines the mapping from
the variables captured by a lambda to the fields that store the
captured values. To be used in IRgen.

llvm-svn: 150235
2012-02-10 07:45:31 +00:00
Ted Kremenek 6eb25628c5 Revert r145999. This turned out to be a bad idea. Unfortunately, 'id' is used so profusely
in many APIs and large codebases that this made the deprecated warning trigger happy to
the point of not being useful.

llvm-svn: 150223
2012-02-10 02:45:47 +00:00
Eli Friedman edb6f5dca1 Make sure we convert struct layout pragmas to attributes for class templates the same way we do for non-template classes. <rdar://problem/10791194>.
llvm-svn: 150221
2012-02-10 02:02:21 +00:00
Aaron Ballman 6d1bebbad9 Switching to using dyn_cast_or_null, and fixing line endings in the test case.
llvm-svn: 150209
2012-02-09 22:16:56 +00:00
Fariborz Jahanian 29082a5f1d objc: If a method is not implemented in the category implementation but
has been declared in its primary class, superclass,
or in one of their protocols, no need to issue unimplemented method. 
// rdar://10823023

llvm-svn: 150206
2012-02-09 21:30:24 +00:00
Eli Friedman 25b0742603 Make sure a variable with a C++ direct initializer triggers jump scope checking. Fixes PR10620 / <rdar://problem/9958362> .
llvm-svn: 150204
2012-02-09 20:13:14 +00:00
Douglas Gregor 940a550f0d Don't allow deduction of a lambda result type from an initializer
list; it is not an expression.

llvm-svn: 150194
2012-02-09 18:40:39 +00:00
Douglas Gregor 7345626a5b Implement return type deduction for lambdas per C++11
[expr.prim.lambda]p4, including the current suggested resolution of
core isue 975, which allows multiple return statements so long as the
types match. ExtWarn when user code is actually making use of this
extension.

llvm-svn: 150168
2012-02-09 10:18:50 +00:00
Douglas Gregor 410d6af994 Restore the appropriate lexical declaration context for a lambda's
function call operator (to the lambda class). This allows us to IRgen
calls to simple (non-capturing) lambdas, e.g.,

  [](int i, int j) -> int { return i + j; }(1, 2)

Eli will be providing test cases as he brings up more IRgen.

llvm-svn: 150166
2012-02-09 08:52:43 +00:00
Douglas Gregor 656bc62a73 Remove the "unsupported" error for lambda expressions. It's annoying,
and rapidly becoming untrue.

llvm-svn: 150165
2012-02-09 08:26:42 +00:00
Douglas Gregor 8962549164 Implement C++ [expr.prim.lambda]p2, which bans lambda expressions in
unevaluated operands. Be certain that we're marking everything
referenced within a capture initializer as odr-used.

llvm-svn: 150163
2012-02-09 08:14:43 +00:00
Richard Smith 4d59eebb49 DR1359: A constexpr constructor does not need to initialize an empty struct or
empty union. This still rejects anonymous member structs or unions which only
contain such empty class types, pending standard wording defining exactly what
an empty class type is.

llvm-svn: 150157
2012-02-09 06:40:58 +00:00
Richard Smith 5a294e6a2c CWG issue 1405: mutable members are allowed in literal types, but can't undergo
lvalue-to-rvalue conversions in constant expressions.

llvm-svn: 150145
2012-02-09 03:29:58 +00:00
Aaron Ballman 3bc84198f4 Attempting to initialize a union member that does not exist no longer crashes.
Patch by Remi Gacogne

llvm-svn: 150144
2012-02-09 03:29:06 +00:00
Douglas Gregor 199cec7673 Implement capture-by-copy for arrays in lambdas.
llvm-svn: 150138
2012-02-09 02:45:47 +00:00
Douglas Gregor fbf19a0eb1 Don't complain about the lack of a constructor for a lambda expression. They are constructed in different ways
llvm-svn: 150136
2012-02-09 02:20:38 +00:00
Douglas Gregor 3d23f78852 When we create a non-static data member in the closure object for a
capture, make sure we actually add the field.

llvm-svn: 150135
2012-02-09 02:12:34 +00:00
Douglas Gregor abecb9ce3c Factor the logic for capturing variables in a lambda into its own
function; it's going to get longer soon. No functionality change.

llvm-svn: 150132
2012-02-09 01:56:40 +00:00
Douglas Gregor ab23d9a9be Along the error path for lambdas, mark the lambda class as invalid and finalize it
llvm-svn: 150130
2012-02-09 01:28:42 +00:00
Aaron Ballman c2a9493a26 Adding support for warning when a non-C compatible user-defined type is returned from an extern "C" function.
Fixes bug 6143

llvm-svn: 150128
2012-02-09 01:21:34 +00:00
Douglas Gregor 8c50e7c5e3 Various interrelated cleanups for lambdas:
- Complete the lambda class when we finish the lambda expression
    (previously, it was left in the "being completed" state)
  - Actually return the LambdaExpr object and bind to the resulting
  temporary when needed.
  - Detect when cleanups are needed while capturing a variable into a
  lambda (e.g., due to default arguments in the copy constructor), and
  make sure those cleanups apply for the whole of the lambda
  expression.
    

llvm-svn: 150123
2012-02-09 00:47:04 +00:00
Douglas Gregor 03dd13cfb6 Factor C++11 lambda expressions implementation into a separate
file. No functionality change.

llvm-svn: 150089
2012-02-08 21:18:48 +00:00
Douglas Gregor c70fe353ea When computing the type of a local variable reference within a lambda,
only add 'const' for variables captured by copy in potentially
evaluated expressions of non-mutable lambdas. (The "by copy" part was
missing).

llvm-svn: 150088
2012-02-08 20:56:50 +00:00