From d3d50a6185a224de3fb02c157cbf447f839d18e6 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 22 Apr 2013 15:19:55 -0400 Subject: [PATCH] N3648 * parser.c (cp_parser_lambda_introducer): Make lambda capture init pedwarn unconditional except in C++1y mode. From-SVN: r198156 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/parser.c | 7 ++++--- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-init.C | 8 -------- .../lambda-deduce-mult.C} | 2 +- gcc/testsuite/g++.dg/cpp1y/lambda-init.C | 8 ++++++++ gcc/testsuite/g++.dg/cpp1y/lambda-init1.C | 13 +++++++++++++ gcc/testsuite/g++.dg/cpp1y/lambda-init2.C | 13 +++++++++++++ gcc/testsuite/g++.dg/cpp1y/lambda-init3.C | 11 +++++++++++ gcc/testsuite/g++.dg/cpp1y/lambda-init4.C | 14 ++++++++++++++ 9 files changed, 68 insertions(+), 12 deletions(-) delete mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-init.C rename gcc/testsuite/g++.dg/{cpp0x/lambda/lambda-deduce-ext.C => cpp1y/lambda-deduce-mult.C} (93%) create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-init.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-init1.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-init2.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-init3.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-init4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index dffab2c2625..34f207f364b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2013-04-22 Jason Merrill + N3648 + * parser.c (cp_parser_lambda_introducer): Make lambda capture init + pedwarn unconditional except in C++1y mode. + * semantics.c (potential_constant_expression_1): Don't crash on 'this' in NSDMI. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 189348251d0..1fbc9bd0a25 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -8518,9 +8518,10 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr) { /* An explicit expression exists. */ cp_lexer_consume_token (parser->lexer); - pedwarn (input_location, OPT_Wpedantic, - "ISO C++ does not allow initializers " - "in lambda expression capture lists"); + if (cxx_dialect < cxx1y) + pedwarn (input_location, 0, + "lambda capture initializers " + "only available with -std=c++1y or -std=gnu++1y"); capture_init_expr = cp_parser_assignment_expression (parser, /*cast_p=*/true, &idk); diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-init.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-init.C deleted file mode 100644 index 03c94e95981..00000000000 --- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-init.C +++ /dev/null @@ -1,8 +0,0 @@ -// Test for the explicit initializer extension -// { dg-options "-std=c++0x" } - -int main() -{ - int j = [i = 2]{sizeof(i); return i;}(); - return (j != 2); -} diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce-ext.C b/gcc/testsuite/g++.dg/cpp1y/lambda-deduce-mult.C similarity index 93% rename from gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce-ext.C rename to gcc/testsuite/g++.dg/cpp1y/lambda-deduce-mult.C index 9b5ab79837f..1181a803647 100644 --- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-deduce-ext.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-deduce-mult.C @@ -1,7 +1,7 @@ // Testcase for an extension to allow return type deduction when the lambda // contains more than just a single return-statement. -// { dg-options -std=c++0x } +// { dg-options -std=c++1y } // { dg-do run } bool b; diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init.C new file mode 100644 index 00000000000..a4436422483 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init.C @@ -0,0 +1,8 @@ +// Test for the explicit initializer extension of C++1y +// { dg-options "-std=c++1y" } + +int main() +{ + int j = [i = 2]{sizeof(i); return i;}(); + return (j != 2); +} diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init1.C new file mode 100644 index 00000000000..6411fca90ba --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init1.C @@ -0,0 +1,13 @@ +// N3648: capture init +// { dg-options "-std=c++1y -w" } +// { dg-do run } + +int main() +{ + int x = 41; + auto r = [x = x+1]{ return x; }(); + if (r != 42) __builtin_abort(); + + static auto *p = &r; + [&x=r]{ if (&x != p) __builtin_abort(); }(); +} diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init2.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init2.C new file mode 100644 index 00000000000..068621dac22 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init2.C @@ -0,0 +1,13 @@ +// N3648: redundancy and capture init +// { dg-options "-std=c++1y -pedantic-errors" } + +int main() +{ + int x = 42; + [=,x]{}; // { dg-error "redundant" } + [=,&x]{}; + [&,&x]{}; // { dg-error "redundant" } + [&,x]{}; + [=,x=24]{}; + [&,&r=x]{}; +} diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init3.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init3.C new file mode 100644 index 00000000000..9044be68771 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init3.C @@ -0,0 +1,11 @@ +// N3648: capture init at non-block scope +// { dg-options "-std=c++1y -w" } +// { dg-do run } + +int i = 42; +int j = [x=i]{ return x; }(); + +int main() +{ + if (j != 42) __builtin_abort(); +} diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init4.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init4.C new file mode 100644 index 00000000000..da4ea37061c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init4.C @@ -0,0 +1,14 @@ +// N3648: capture init example from paper +// { dg-options "-std=c++1y" } +// { dg-do run } + +int x = 4; +auto y = [&r = x, x = x+1]()->int { + r += 2; + return x+2; +}(); // Updates ::x to 6, and initializes y to 7. + +int main() +{ + if (x != 6 || y != 7) __builtin_abort(); +} -- 2.30.2