reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
// FIXME: should compile
// Test for blocks with explicit return type specified.

typedef float * PF;
float gf;

@interface NSView
  - (id) some_method_that_returns_id;
@end

NSView *some_object;

void some_func (NSView * (^) (id));

typedef struct dispatch_item_s *dispatch_item_t;
typedef void (^completion_block_t)(void);

typedef double (^myblock)(int);
double test(myblock I);

int main() {
  __block int x = 1;
  __block int y = 2;

  (void)^void *{ return 0; };

  (void)^float(float y){ return y; };

  (void)^double (float y, double d) {
    if (y)
      return d;
    else
      return y;
  };

  const char * (^chb) (int flag, const char *arg, char *arg1) = ^ const char * (int flag, const char *arg, char *arg1) {
    if (flag)
      return 0;
    if (flag == 1)
      return arg;
    else if (flag == 2)
      return "";
    return arg1; 
  };

  (void)^PF { return &gf; };

  some_func(^ NSView * (id whatever) { return [some_object some_method_that_returns_id]; });

  double res = test(^(int z){x = y+z; return (double)z; });
}

void func() {
  completion_block_t X;

  completion_block_t (^blockx)(dispatch_item_t) = ^completion_block_t (dispatch_item_t item) {
    return X;
  };

  completion_block_t (^blocky)(dispatch_item_t) = ^(dispatch_item_t item) {
    return X;
  };

  blockx = blocky;
}


// intent: block taking int returning block that takes char,int and returns int
int (^(^block)(double x))(char, short);

void foo() {
   int one = 1;
   block = ^(double x){ return ^(char c, short y) { return one + c + y; };};  // expected-error {{returning block that lives on the local stack}}
   // or:
   block = ^(double x){ return ^(char c, short y) { return one + (int)c + y; };};  // expected-error {{returning block that lives on the local stack}}
}