llvm-project/clang/test/Parser/objcxx0x-lambda-expressions.mm
Richard Smith 42b1057244 N3922: direct-list-initialization of an auto-typed variable no longer deduces a
std::initializer_list<T> type. Instead, the list must contain a single element
and the type is deduced from that.

In Clang 3.7, we warned by default on all the cases that would change meaning
due to this change. In Clang 3.8, we will support only the new rules -- per
the request in N3922, this change is applied as a Defect Report against earlier
versions of the C++ standard.

This change is not entirely trivial, because for lambda init-captures we
previously did not track the difference between direct-list-initialization and
copy-list-initialization. The difference was not previously observable, because
the two forms of initialization always did the same thing (the elements of the
initializer list were always copy-initialized regardless of the initialization
style used for the init-capture).

llvm-svn: 252688
2015-11-11 01:36:17 +00:00

57 lines
1.8 KiB
Plaintext

// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -Wno-c++1y-extensions -std=c++11 %s
class C {
id get(int);
void f() {
int foo, bar, baz;
// fail to parse as a lambda introducer, so we get objc message parsing errors instead
[foo,+] {}; // expected-error {{expected expression}}
[]; // expected-error {{expected body of lambda expression}}
[=,foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}}
[&this] {}; // expected-error {{cannot take the address of an rvalue of type 'C *'}}
[] {};
[=] (int i) {};
[&] (int) mutable -> void {};
[foo,bar] () { return 3; };
[=,&foo] () {};
[this] () {};
[foo(bar)] () {};
[foo = bar] () {};
[foo{bar}] () {};
[foo = {bar}] () {}; // expected-error {{<initializer_list>}}
[foo(bar) baz] () {}; // expected-error {{called object type 'int' is not a function}}
[foo(bar), baz] () {}; // ok
[foo = bar baz]; // expected-warning {{receiver type 'int'}} expected-warning {{instance method '-baz'}}
[get(bar) baz]; // expected-warning {{instance method '-baz'}}
[get(bar), baz]; // expected-error {{expected body of lambda}}
[foo = bar ++ baz]; // expected-warning {{receiver type 'int'}} expected-warning {{instance method '-baz'}}
[foo = bar + baz]; // expected-error {{expected body of lambda}}
[foo = { bar, baz }]; // expected-error {{<initializer_list>}} expected-error {{expected body of lambda}}
[foo = { bar } baz ]; // expected-warning {{receiver type 'int'}} expected-warning {{instance method '-baz'}}
[foo = { bar }, baz ]; // expected-error {{<initializer_list>}} expected-error {{expected body of lambda}}
}
};
struct Func {
template <typename F>
Func(F&&);
};
int getInt();
void test() {
[val = getInt()]() { };
Func{
[val = getInt()]() { }
};
}