From: Nathan Sidwell Date: Tue, 31 Jan 2017 18:05:37 +0000 (+0000) Subject: re PR c++/67273 (Incorrect -Wshadow warning with generic lambdas) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=de3fbef690ab0c8c4631ea0359d0500fa22ff1a9;p=gcc.git re PR c++/67273 (Incorrect -Wshadow warning with generic lambdas) PR c++/67273 PR c++/79253 * pt.c: (instantiate_decl): Push to top level when current function scope doesn't match. Only push lmabda scope stack when pushing to top. PR c++/67273 PR c++/79253 * g++.dg/cpp1y/pr67273.C: New. * g++.dg/cpp1y/pr79253.C: New. From-SVN: r245067 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5df2f723c71..78a5725dc6d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,11 @@ 2017-01-31 Nathan Sidwell + PR c++/67273 + PR c++/79253 + * pt.c: (instantiate_decl): Push to top level when current + function scope doesn't match. Only push lmabda scope stack when + pushing to top. + * cp-tree.h (instantiate_decl): Make defer_ok bool. * pt.c: Fix instantiate_decl calls to pass true/false not 0/1 (instantiate_decl): Simplify and reorder state saving and restoration. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index bd39ee383e1..c69c27063e8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -22666,20 +22666,21 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p) goto out; } - bool nested; + bool push_to_top, nested; tree fn_context; fn_context = decl_function_context (d); - nested = (current_function_decl != NULL_TREE); + nested = current_function_decl != NULL_TREE; + push_to_top = !(nested && fn_context == current_function_decl); + vec omp_privatization_save; if (nested) save_omp_privatization_clauses (omp_privatization_save); - if (!fn_context) + if (push_to_top) push_to_top_level (); else { - if (nested) - push_function_context (); + push_function_context (); cp_unevaluated_operand = 0; c_inhibit_evaluation_warnings = 0; } @@ -22756,7 +22757,7 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p) block = push_stmt_list (); else { - if (LAMBDA_FUNCTION_P (d)) + if (push_to_top && LAMBDA_FUNCTION_P (d)) { /* When instantiating a lambda's templated function operator, we need to push the non-lambda class scope @@ -22849,9 +22850,9 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p) /* We're not deferring instantiation any more. */ TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (d)) = 0; - if (!fn_context) + if (push_to_top) pop_from_top_level (); - else if (nested) + else pop_function_context (); if (nested) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 675c190bb1a..922fe645755 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2017-01-31 Nathan Sidwell + + PR c++/67273 + PR c++/79253 + * g++.dg/cpp1y/pr67273.C: New. + * g++.dg/cpp1y/pr79253.C: New. + 2017-01-31 Nathan Sidwell PR c++/79264 diff --git a/gcc/testsuite/g++.dg/cpp1y/pr67273.C b/gcc/testsuite/g++.dg/cpp1y/pr67273.C new file mode 100644 index 00000000000..d2bc0350212 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/pr67273.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++14 } } +// { dg-additional-options "-Wshadow" } + +// pr67273 bogus warning about shadowing. + + +template void Foo (T &&lambda) +{ + int ARG = 2; + lambda (1); +} + +void Baz () +{ + Foo ([] (auto &&ARG) {}); +} diff --git a/gcc/testsuite/g++.dg/cpp1y/pr79253.C b/gcc/testsuite/g++.dg/cpp1y/pr79253.C new file mode 100644 index 00000000000..b15efe8873f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/pr79253.C @@ -0,0 +1,33 @@ +// { dg-do compile { target c++14 } } +// PR 79253 ICE instantiating lambda body. + +template struct A; +template > class B {}; +template void foo (U, V) { T (0, 0); } +struct C {}; +template