From 7768f20b0a08f8f735de9f4088945023cce0230b Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 21 Nov 2017 09:39:57 +0100 Subject: [PATCH] P0428R2 - familiar template syntax for generic lambdas P0428R2 - familiar template syntax for generic lambdas * parser.c (cp_parser_lambda_declarator_opt): Don't pedwarn for cxx2a and above, reword pedwarn for C++14/C++17. * g++.dg/cpp1y/lambda-generic-x.C: Adjust warnings and limit to c++17_down target. * g++.dg/cpp1y/lambda-generic-dep.C: Likewise. * g++.dg/cpp1y/lambda-generic-77914.C: Adjust error and limit to c++17_down target. * g++.dg/cpp2a/lambda-generic1.C: New test. * g++.dg/cpp2a/lambda-generic2.C: New test. * g++.dg/cpp2a/lambda-generic3.C: New test. * g++.dg/cpp2a/lambda-generic4.C: New test. * g++.dg/cpp2a/lambda-generic5.C: New test. From-SVN: r254991 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 5 +++-- gcc/testsuite/ChangeLog | 12 ++++++++++++ gcc/testsuite/g++.dg/cpp1y/lambda-generic-77914.C | 2 +- gcc/testsuite/g++.dg/cpp1y/lambda-generic-dep.C | 2 +- gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C | 8 ++++---- gcc/testsuite/g++.dg/cpp2a/lambda-generic1.C | 9 +++++++++ gcc/testsuite/g++.dg/cpp2a/lambda-generic2.C | 7 +++++++ gcc/testsuite/g++.dg/cpp2a/lambda-generic3.C | 8 ++++++++ gcc/testsuite/g++.dg/cpp2a/lambda-generic4.C | 8 ++++++++ gcc/testsuite/g++.dg/cpp2a/lambda-generic5.C | 6 ++++++ 11 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic1.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic2.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic3.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic4.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 56d466dfb4c..db9403455c4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-11-21 Jakub Jelinek + + P0428R2 - familiar template syntax for generic lambdas + * parser.c (cp_parser_lambda_declarator_opt): Don't pedwarn + for cxx2a and above, reword pedwarn for C++14/C++17. + 2017-11-20 David Malcolm PR c/81404 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 82807690c88..b0617048209 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -10512,9 +10512,10 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) pedwarn (parser->lexer->next_token->location, 0, "lambda templates are only available with " "-std=c++14 or -std=gnu++14"); - else + else if (cxx_dialect < cxx2a) pedwarn (parser->lexer->next_token->location, OPT_Wpedantic, - "ISO C++ does not support lambda templates"); + "lambda templates are only available with " + "-std=c++2a or -std=gnu++2a"); cp_lexer_consume_token (parser->lexer); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 05638e790dc..3901db4b4b8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,17 @@ 2017-11-21 Jakub Jelinek + P0428R2 - familiar template syntax for generic lambdas + * g++.dg/cpp1y/lambda-generic-x.C: Adjust warnings and limit + to c++17_down target. + * g++.dg/cpp1y/lambda-generic-dep.C: Likewise. + * g++.dg/cpp1y/lambda-generic-77914.C: Adjust error and limit + to c++17_down target. + * g++.dg/cpp2a/lambda-generic1.C: New test. + * g++.dg/cpp2a/lambda-generic2.C: New test. + * g++.dg/cpp2a/lambda-generic3.C: New test. + * g++.dg/cpp2a/lambda-generic4.C: New test. + * g++.dg/cpp2a/lambda-generic5.C: New test. + PR c++/83059 * c-c++-common/pr83059.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-77914.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-77914.C index d069c33c93d..a57903aba33 100644 --- a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-77914.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-77914.C @@ -4,6 +4,6 @@ int main () { - auto l = [] () {}; // { dg-error "does not support lambda templates" } + auto l = [] () {}; // { dg-error "lambda templates are only available with" "" { target c++17_down } } l.operator () (); } diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-dep.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-dep.C index c66d393d6b4..982a155e777 100644 --- a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-dep.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-dep.C @@ -27,7 +27,7 @@ struct S { int main() { - auto f = [] (T const& s) mutable { // { dg-warning "does not support lambda templates" } + auto f = [] (T const& s) mutable { // { dg-warning "lambda templates are only available with" "" { target c++17_down } } typename T::N x; return x.test (); }; diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C index b37a6147526..0926a5e363b 100644 --- a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C @@ -6,17 +6,17 @@ int main() { - auto glambda = [] (A a, B&& b) { return a < b; }; // { dg-warning "does not support lambda templates" } + auto glambda = [] (A a, B&& b) { return a < b; }; // { dg-warning "lambda templates are only available with" "" { target c++17_down } } bool b = glambda(3, 3.14); // OK - auto vglambda = [] (P printer) { // { dg-warning "does not support lambda templates" } + auto vglambda = [] (P printer) { // { dg-warning "lambda templates are only available with" "" { target c++17_down } } return [=] (T&& ... ts) { // OK: ts is a function parameter pack - printer(std::forward(ts)...); // { dg-warning "does not support lambda templates" "" { target *-*-* } .-1 } + printer(std::forward(ts)...); // { dg-warning "lambda templates are only available with" "" { target c++17_down } .-1 } return [=]() { printer(ts ...); }; }; }; - auto p = vglambda( [] (A v1, B v2, C v3) { std::cout << v1 << v2 << v3; } ); diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic1.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic1.C new file mode 100644 index 00000000000..9f6304bbc69 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic1.C @@ -0,0 +1,9 @@ +// P0428R2 +// { dg-do compile { target c++14 } } + +int i = [](int i, auto a) { return i; }(3, 4); +int j = [](T t, int i) { return i; }(3, 4); // { dg-error "lambda templates are only available with" "" { target c++17_down } } +int k[2] = { 5, 6 }; +int l = [](T *p) { return *p; }(k); // { dg-error "lambda templates are only available with" "" { target c++17_down } } +int m = [](T (&a)[N]) { return a[N - 1]; }(k); // { dg-error "lambda templates are only available with" "" { target c++17_down } } +int n = [](T a, auto b) { return a + b; }(7, 8); // { dg-error "lambda templates are only available with" "" { target c++17_down } } diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic2.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic2.C new file mode 100644 index 00000000000..6116639f871 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic2.C @@ -0,0 +1,7 @@ +// P0428R2 +// { dg-do compile } + +int j = [](T t, int i) { return i; }(3, 4); +// { dg-error "lambda templates are only available with" "" { target c++17_down } .-1 } +// { dg-error "lambda expressions only available with" "" { target c++98_only } .-2 } +// { dg-error "invalid use of 'auto'" "" { target c++98_only } .-3 } diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic3.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic3.C new file mode 100644 index 00000000000..b0d525e80d7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic3.C @@ -0,0 +1,8 @@ +// P0428R2 +// { dg-do compile } +// { dg-options "-Wpedantic" } + +int j = [](T t, int i) { return i; }(3, 4); +// { dg-warning "lambda templates are only available with" "" { target c++17_down } .-1 } +// { dg-warning "lambda expressions only available with" "" { target c++98_only } .-2 } +// { dg-error "invalid use of 'auto'" "" { target c++98_only } .-3 } diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic4.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic4.C new file mode 100644 index 00000000000..393e8523f08 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic4.C @@ -0,0 +1,8 @@ +// P0428R2 +// { dg-do compile } +// { dg-options "-Wno-pedantic" } + +int j = [](T t, int i) { return i; }(3, 4); +// { dg-warning "lambda templates are only available with" "" { target c++11_down } .-1 } +// { dg-warning "lambda expressions only available with" "" { target c++98_only } .-2 } +// { dg-error "invalid use of 'auto'" "" { target c++98_only } .-3 } diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic5.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic5.C new file mode 100644 index 00000000000..e608e9520bf --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic5.C @@ -0,0 +1,6 @@ +// P0428R2 +// { dg-do compile } +// { dg-options "-std=c++2a" } + +int j = [](T t, int i) { return i; }(3, 4); +// { dg-bogus "lambda templates are only available with" "" { target c++2a } .-1 } -- 2.30.2