diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-02-22 17:32:19 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-02-22 17:32:19 +0000 |
commit | b734e2437d3c4b20a28b448e75cb45ef71f0b518 (patch) | |
tree | 4675c832b46f567514da0975e70fcc4417a34415 /test/CXX/expr/expr.prim/expr.prim.lambda | |
parent | 33deb35535aebe81bed0eaf5c14f3032276a086e (diff) |
Teach overload resolution to prefer user-defined conversion via a
lambda closure type's function pointer conversion over user-defined
conversion via a lambda closure type's block pointer conversion,
always. This is a preference for more-standard code (since blocks
are an extension) and a nod to efficiency, since function pointers
don't require any memory management. Fixes PR12063.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151170 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX/expr/expr.prim/expr.prim.lambda')
-rw-r--r-- | test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm b/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm index f6a8db23e9..0c3fdb2d80 100644 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm +++ b/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm @@ -55,3 +55,34 @@ void nesting() { }(); }(); } + +namespace overloading { + void bool_conversion() { + if ([](){}) { + } + + bool b = []{}; + b = (bool)[]{}; + } + + void conversions() { + int (*fp)(int) = [](int x) { return x + 1; }; + fp = [](int x) { return x + 1; }; + + typedef int (*func_ptr)(int); + fp = (func_ptr)[](int x) { return x + 1; }; + + int (^bp)(int) = [](int x) { return x + 1; }; + bp = [](int x) { return x + 1; }; + + typedef int (^block_ptr)(int); + bp = (block_ptr)[](int x) { return x + 1; }; + } + + int &accept_lambda_conv(int (*fp)(int)); + float &accept_lambda_conv(int (^bp)(int)); + + void call_with_lambda() { + int &ir = accept_lambda_conv([](int x) { return x + 1; }); + } +} |