From: Jakub Jelinek Date: Wed, 25 Jan 2017 20:51:10 +0000 (+0100) Subject: re PR c++/77914 (Wrong lambda definition accepted) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0e3438689a6ffc4851ba8162306e5a1709b3b905;p=gcc.git re PR c++/77914 (Wrong lambda definition accepted) PR c++/77914 * parser.c (cp_parser_lambda_declarator_opt): Pedwarn with OPT_Wpedantic on lambda templates for -std=c++14 and higher. * g++.dg/cpp1y/lambda-generic-77914.C: New test. * g++.dg/cpp1y/lambda-generic-dep.C: Add -pedantic to dg-options, expect a warning. * g++.dg/cpp1y/lambda-generic-x.C: Add -Wpedantic to dg-options, expect warnings. * g++.dg/cpp1y/lambda-generic-mixed.C: Add empty dg-options. * g++.dg/cpp1y/pr59636.C: Likewise. * g++.dg/cpp1y/pr60190.C: Likewise. From-SVN: r244907 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 47eaa55032f..dc098b2a723 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-01-25 Jakub Jelinek + + PR c++/77914 + * parser.c (cp_parser_lambda_declarator_opt): Pedwarn with + OPT_Wpedantic on lambda templates for -std=c++14 and higher. + 2017-01-25 Maxim Ostapenko PR lto/79061 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4ab0b6974d6..372a01e147a 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -10174,6 +10174,9 @@ 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 + pedwarn (parser->lexer->next_token->location, OPT_Wpedantic, + "ISO C++ does not support lambda templates"); cp_lexer_consume_token (parser->lexer); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9deb57de7e3..e82fb4c9455 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2017-01-25 Jakub Jelinek + + PR c++/77914 + * g++.dg/cpp1y/lambda-generic-77914.C: New test. + * g++.dg/cpp1y/lambda-generic-dep.C: Add -pedantic to dg-options, + expect a warning. + * g++.dg/cpp1y/lambda-generic-x.C: Add -Wpedantic to dg-options, + expect warnings. + * g++.dg/cpp1y/lambda-generic-mixed.C: Add empty dg-options. + * g++.dg/cpp1y/pr59636.C: Likewise. + * g++.dg/cpp1y/pr60190.C: Likewise. + 2017-01-25 Bin Cheng * gcc.dg/vect/vect-24.c: Remove xfail on ARM targets. diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-77914.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-77914.C new file mode 100644 index 00000000000..d069c33c93d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-77914.C @@ -0,0 +1,9 @@ +// PR c++/77914 +// { dg-do compile { target c++14 } } + +int +main () +{ + auto l = [] () {}; // { dg-error "does not support lambda templates" } + 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 dbf8b70f862..c66d393d6b4 100644 --- a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-dep.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-dep.C @@ -1,5 +1,6 @@ // Generic lambda type dependence test part from N3690 5.1.2.12 // { dg-do compile { target c++14 } } +// { dg-options "-pedantic" } void f(int, const int (&)[2] = {}) { } // #1 void f(const int&, const int (&)[1]) { } // #2 @@ -26,7 +27,7 @@ struct S { int main() { - auto f = [] (T const& s) mutable { + auto f = [] (T const& s) mutable { // { dg-warning "does not support lambda templates" } typename T::N x; return x.test (); }; diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-mixed.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-mixed.C index 59b5ccaa957..aa968247819 100644 --- a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-mixed.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-mixed.C @@ -1,5 +1,6 @@ // Mixed explicit and implicit generic lambda test. // { dg-do compile { target c++14 } } +// { dg-options "" } int main() { diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C index 5334091ef5f..b37a6147526 100644 --- a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-x.C @@ -1,21 +1,22 @@ // Explicit generic lambda test from N3690 5.1.2.5 // { dg-do compile { target c++14 } } +// { dg-options "-Wpedantic" } #include int main() { - auto glambda = [] (A a, B&& b) { return a < b; }; + auto glambda = [] (A a, B&& b) { return a < b; }; // { dg-warning "does not support lambda templates" } bool b = glambda(3, 3.14); // OK - auto vglambda = [] (P printer) { + auto vglambda = [] (P printer) { // { dg-warning "does not support lambda templates" } return [=] (T&& ... ts) { // OK: ts is a function parameter pack - printer(std::forward(ts)...); + printer(std::forward(ts)...); // { dg-warning "does not support lambda templates" "" { target *-*-* } .-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/cpp1y/pr59636.C b/gcc/testsuite/g++.dg/cpp1y/pr59636.C index 847cecdf5a5..271491ee23c 100644 --- a/gcc/testsuite/g++.dg/cpp1y/pr59636.C +++ b/gcc/testsuite/g++.dg/cpp1y/pr59636.C @@ -1,4 +1,5 @@ // PR c++/59636 // { dg-do compile { target c++14 } } +// { dg-options "" } auto f = []() { return []<>() {}; }; // { dg-error "expected identifier" } diff --git a/gcc/testsuite/g++.dg/cpp1y/pr60190.C b/gcc/testsuite/g++.dg/cpp1y/pr60190.C index 9e439ceb9ea..f2d1bbf6112 100644 --- a/gcc/testsuite/g++.dg/cpp1y/pr60190.C +++ b/gcc/testsuite/g++.dg/cpp1y/pr60190.C @@ -1,4 +1,5 @@ // PR c++/60190 // { dg-do compile { target c++14 } } +// { dg-options "" } auto f = []() -> int() {}; // { dg-error "returning a function|expected" }