blob: b9b8cd76c011ff1477dd14aa8b5fced443467951 [file] [log] [blame]
Richard Smith5b013f52013-09-28 05:38:27 +00001// RUN: %clang_cc1 -std=c++11 %s -verify -Wno-c++1y-extensions
Douglas Gregor53a9bdf2012-02-01 01:18:43 +00002
3class X0 {
4 void explicit_capture() {
5 int foo;
6
Douglas Gregor656bc622012-02-09 08:26:42 +00007 (void)[foo, foo] () {}; // expected-error {{'foo' can appear only once}}
8 (void)[this, this] () {}; // expected-error {{'this' can appear only once}}
9 (void)[=, foo] () {}; // expected-error {{'&' must precede a capture when}}
10 (void)[=, &foo] () {};
Douglas Gregora1bffa22012-02-10 17:46:20 +000011 (void)[=, this] () {}; // expected-error {{'this' cannot be explicitly captured}}
Douglas Gregor656bc622012-02-09 08:26:42 +000012 (void)[&, foo] () {};
13 (void)[&, &foo] () {}; // expected-error {{'&' cannot precede a capture when}}
14 (void)[&, this] () {};
Douglas Gregor53a9bdf2012-02-01 01:18:43 +000015 }
16};
Douglas Gregor136b2f22012-02-10 09:37:05 +000017
Douglas Gregora1bffa22012-02-10 17:46:20 +000018struct S2 {
19 void f(int i);
20 void g(int i);
21};
Douglas Gregor136b2f22012-02-10 09:37:05 +000022
23void S2::f(int i) {
24 (void)[&, i]{ };
25 (void)[&, &i]{ }; // expected-error{{'&' cannot precede a capture when the capture default is '&'}}
Douglas Gregora1bffa22012-02-10 17:46:20 +000026 (void)[=, this]{ }; // expected-error{{'this' cannot be explicitly captured}}
27 (void)[=]{ this->g(i); };
Douglas Gregor136b2f22012-02-10 09:37:05 +000028 (void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
Richard Smithba71c082013-05-16 06:20:58 +000029 (void)[i(0), i(1)]{ }; // expected-error{{'i' can appear only once in a capture list}}
30 (void)[i, i(1)]{ }; // expected-error{{'i' can appear only once in a capture list}}
31 (void)[i(0), i]{ }; // expected-error{{'i' can appear only once in a capture list}}
Douglas Gregor136b2f22012-02-10 09:37:05 +000032}