From: Paolo Carlini Date: Sun, 29 May 2016 08:05:30 +0000 (+0000) Subject: re PR c++/71105 (lambdas with default captures improperly have function pointer conve... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b6d4f8e8549572f272cc03869a64d0d02af7ec70;p=gcc.git re PR c++/71105 (lambdas with default captures improperly have function pointer conversions) /cp 2016-05-29 Paolo Carlini PR c++/71105 * lambda.c (maybe_add_lambda_conv_op): Early return also when LAMBDA_EXPR_DEFAULT_CAPTURE_MODE != CPLD_NONE. /testsuite 2016-05-29 Paolo Carlini PR c++/71105 * g++.dg/cpp0x/lambda/lambda-conv11.C: New. * g++.dg/cpp1y/lambda-conv1.C: Likewise. * g++.dg/cpp1y/lambda-conv2.C: Likewise. From-SVN: r236859 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 27fdbe1497a..7857e7fdce8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2016-05-29 Paolo Carlini + + PR c++/71105 + * g++.dg/cpp0x/lambda/lambda-conv11.C: New. + * g++.dg/cpp1y/lambda-conv1.C: Likewise. + * g++.dg/cpp1y/lambda-conv2.C: Likewise. + 2016-05-27 Jan Hubicka * gcc.dg/tree-ssa/prefetch-5.c: Remove xfail. diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv11.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv11.C new file mode 100644 index 00000000000..4b8d6487f5c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv11.C @@ -0,0 +1,10 @@ +// PR c++/71105 +// { dg-do compile { target c++11 } } + +void foo() +{ + int i; + static_cast([i]{}); // { dg-error "invalid static_cast" } + static_cast([=]{}); // { dg-error "invalid static_cast" } + static_cast([&]{}); // { dg-error "invalid static_cast" } +} diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-conv1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-conv1.C new file mode 100644 index 00000000000..2e4ec4964d5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-conv1.C @@ -0,0 +1,13 @@ +// PR c++/71105 +// { dg-do compile { target c++14 } } + +void foo() +{ + int i; + static_cast([i](auto){}); // { dg-error "invalid static_cast" } + static_cast([=](auto){}); // { dg-error "invalid static_cast" } + static_cast([&](auto){}); // { dg-error "invalid static_cast" } + static_cast([i](auto x){ return x; }); // { dg-error "invalid static_cast" } + static_cast([=](auto x){ return x; }); // { dg-error "invalid static_cast" } + static_cast([&](auto x){ return x; }); // { dg-error "invalid static_cast" } +} diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-conv2.C b/gcc/testsuite/g++.dg/cpp1y/lambda-conv2.C new file mode 100644 index 00000000000..45c0f3fe186 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-conv2.C @@ -0,0 +1,23 @@ +// PR c++/71105 +// { dg-do compile { target c++14 } } + +template T declval(); +template struct is_same +{ static constexpr bool value = false; }; +template struct is_same +{ static constexpr bool value = true; }; + +template +struct indirected : F { + indirected(F f) : F(f) {} + template + auto operator()(I i) -> decltype(declval()(*i)) { + return static_cast(*this)(*i); + } +}; + +int main() { + auto f = [=](auto i) { return i + i; }; + auto i = indirected{f}; + static_assert(is_same())), int>::value, ""); +}