aboutsummaryrefslogtreecommitdiff
path: root/test/SemaCXX/lambda-expressions.cpp
blob: db934c3ab77b6a8014f70255e0195e184281f2e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s

namespace std { class type_info; };

namespace ExplicitCapture {
  int GlobalVar; // expected-note {{declared here}}

  namespace N {
    int AmbiguousVar; // expected-note {{candidate}}
  }
  int AmbiguousVar; // expected-note {{candidate}}
  using namespace N;

  class C {
    int Member;

    static void Overload(int);
    void Overload();
    virtual C& Overload(float);

    void ExplicitCapture() {
      int foo;

      [foo, foo] () {}; // expected-error {{'foo' can appear only once}} expected-error {{not supported yet}}
      [this, this] () {}; // expected-error {{'this' can appear only once}} expected-error {{not supported yet}}
      [=, foo] () {}; // expected-error {{'&' must precede a capture when}} expected-error {{not supported yet}}
      [=, &foo] () {}; // expected-error {{not supported yet}}
      [=, this] () {}; // expected-error {{'this' cannot appear}} expected-error {{not supported yet}}
      [&, foo] () {}; // expected-error {{not supported yet}}
      [&, &foo] () {}; // expected-error {{'&' cannot precede a capture when}} expected-error {{not supported yet}}
      [&, this] () {}; // expected-error {{not supported yet}}
      [&Overload] () {}; // expected-error {{does not name a variable}} expected-error {{not supported yet}}
      [&GlobalVar] () {}; // expected-error {{does not have automatic storage duration}} expected-error {{not supported yet}}
      [&AmbiguousVar] () {} // expected-error {{reference to 'AmbiguousVar' is ambiguous}} expected-error {{not supported yet}}
      [&Globalvar] () {}; // expected-error {{use of undeclared identifier 'Globalvar'; did you mean 'GlobalVar}}
    }

    void ImplicitThisCapture() {
      [](){(void)Member;}; // expected-error {{'this' cannot be implicitly captured in this context}} expected-error {{not supported yet}}
      [&](){(void)Member;}; // expected-error {{not supported yet}}
      [this](){(void)Member;}; // expected-error {{not supported yet}}
      [this]{[this]{};};// expected-error 2 {{not supported yet}}
      []{[this]{};};// expected-error {{'this' cannot be implicitly captured in this context}} expected-error 2 {{not supported yet}}
      []{Overload(3);}; // expected-error {{not supported yet}}
      []{Overload();}; // expected-error {{'this' cannot be implicitly captured in this context}} expected-error {{not supported yet}}
      []{(void)typeid(Overload());};// expected-error {{not supported yet}}
      []{(void)typeid(Overload(.5f));};// expected-error {{'this' cannot be implicitly captured in this context}} expected-error {{not supported yet}}
    }
  };

  void f() {
    [this] () {}; // expected-error {{invalid use of 'this'}} expected-error {{not supported yet}}
  }
}

namespace ReturnDeduction {
  void test() {
    [](){ return 1; }; // expected-error {{not supported yet}}
    [](){ return 1; }; // expected-error {{not supported yet}}
    [](){ return ({return 1; 1;}); }; // expected-error {{not supported yet}}
    [](){ return ({return 'c'; 1;}); }; // expected-error {{not supported yet}} expected-error {{must match previous return type}}
    []()->int{ return 'c'; return 1; }; // expected-error {{not supported yet}}
    [](){ return 'c'; return 1; }; // expected-error {{not supported yet}} expected-error {{must match previous return type}}
    // FIXME: Need to check structure of lambda body 
    [](){ return 1; return 1; }; // expected-error {{not supported yet}}
  }
}