This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] PR c++/79133
- From: Ville Voutilainen <ville dot voutilainen at gmail dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Paolo Carlini <paolo dot carlini at oracle dot com>, gcc-patches List <gcc-patches at gcc dot gnu dot org>, Nathan Sidwell <nathan at acm dot org>
- Date: Tue, 7 Aug 2018 13:43:53 +0300
- Subject: Re: [C++ PATCH] PR c++/79133
- References: <CAFk2RUY6GAaErLo-joHP+UWkQwCSFM5zwa5p5WoyQd419BrKsQ@mail.gmail.com> <07a4ccdc-b53b-ed8b-3362-fef6b6e5bfe2@oracle.com> <CAFk2RUZ03KF3wRwC6rq-CBhTXhpGk4qEq-CFSUKD5Qpd_XNvPA@mail.gmail.com> <CAFk2RUYYXSPw61YgcU3kc7mJ5wcdw-NgBrukiSso4W-D-4j0sA@mail.gmail.com> <CAFk2RUaR7BT-6hhD6zO3ZsUN4hdhmsoLePnjSgX+v04kRqvMGA@mail.gmail.com> <bbad4468-d023-2dd1-ae24-d6ad158b1bac@oracle.com> <CAFk2RUao5WnnVd+3zHtD+dA5QBkpD-gTG3SN8uKCDJ=SH7Pesw@mail.gmail.com> <b8171725-eec2-71be-a539-a0265d8e94bf@oracle.com> <CAFk2RUaBgxzZ-mbACoi2xSe5JdYXn=ZupNunuHj5SV5m=VyJiw@mail.gmail.com> <CAFk2RUZwkbx2tofRTR=ucceW+SQ0TJxWmc1-FwdWztONLpH-cg@mail.gmail.com> <ad98b93c-d8f7-cfd4-d985-295e66ee745f@redhat.com>
On 7 August 2018 at 13:12, Jason Merrill <jason@redhat.com> wrote:
> Maybe put this block first rather than add !is_capture_proxy to the if
> condition?
Thus?
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 3aafb0f..0faf739 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -2640,13 +2640,29 @@ check_local_shadow (tree decl)
|| TREE_CODE (decl) == TYPE_DECL)))
&& DECL_FUNCTION_SCOPE_P (old)
&& (!DECL_ARTIFICIAL (decl)
+ || is_capture_proxy (decl)
|| DECL_IMPLICIT_TYPEDEF_P (decl)
|| (VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))))
{
/* DECL shadows a local thing possibly of interest. */
+ /* DR 2211: check that captures and parameters
+ do not have the same name. */
+ if (is_capture_proxy (decl))
+ {
+ if (current_lambda_expr ()
+ && DECL_CONTEXT (old) == lambda_function (current_lambda_expr ())
+ && TREE_CODE (old) == PARM_DECL
+ && DECL_NAME (decl) != this_identifier)
+ {
+ error_at (DECL_SOURCE_LOCATION (old),
+ "lambda parameter %qD "
+ "previously declared as a capture", old);
+ }
+ return;
+ }
/* Don't complain if it's from an enclosing function. */
- if (DECL_CONTEXT (old) == current_function_decl
+ else if (DECL_CONTEXT (old) == current_function_decl
&& TREE_CODE (decl) != PARM_DECL
&& TREE_CODE (old) == PARM_DECL)
{
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow3.C
new file mode 100644
index 0000000..8364321
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow3.C
@@ -0,0 +1,6 @@
+// { dg-do compile { target c++11 } }
+
+int main() {
+ int x = 42;
+ auto lambda = [x](int x) {}; // { dg-error "previously declared as a capture" }
+}
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic18.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic18.C
new file mode 100644
index 0000000..1eb9cce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-variadic18.C
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++14 } }
+
+int main() {
+ int x = 42;
+ auto lambda2 = [x=x](int x) {}; // { dg-error "previously declared as a capture" }
+ auto lambda3 = [x](auto... x) {}; // { dg-error "previously declared as a capture" }
+ auto lambda4 = [](auto... x) {
+ auto lambda5 = [x...](auto... x) {}; // { dg-error "previously declared as a capture" }
+ auto lambda6 = [x...](int x) {}; // { dg-error "previously declared as a capture" }
+ };
+}