public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: ICE with redundant capture [PR108829]
@ 2023-02-17 18:58 Marek Polacek
  2023-02-17 20:00 ` Patrick Palka
  0 siblings, 1 reply; 7+ messages in thread
From: Marek Polacek @ 2023-02-17 18:58 UTC (permalink / raw)
  To: Jason Merrill, GCC Patches

Here we crash in is_capture_proxy:

  /* Location wrappers should be stripped or otherwise handled by the
     caller before using this predicate.  */
  gcc_checking_assert (!location_wrapper_p (decl));

so fixed as the comment suggests.  We only crash with the redundant
capture:

  int abyPage = [=, abyPage] { ... }

because prune_lambda_captures is only called when there was a default
capture, and with [=] only abyPage won't be in LAMBDA_EXPR_CAPTURE_LIST.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12?

	PR c++/108829

gcc/cp/ChangeLog:

	* lambda.cc (var_to_maybe_prune): Strip location wrappers before
	checking for a capture proxy.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/lambda/lambda-108829.C: New test.
---
 gcc/cp/lambda.cc                                  |  1 +
 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C | 11 +++++++++++
 2 files changed, 12 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C

diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index c752622816d..a12b9c183c2 100644
--- a/gcc/cp/lambda.cc
+++ b/gcc/cp/lambda.cc
@@ -1700,6 +1700,7 @@ var_to_maybe_prune (tree cap)
     return NULL_TREE;
 
   tree init = TREE_VALUE (cap);
+  STRIP_ANY_LOCATION_WRAPPER (init);
   if (is_normal_capture_proxy (init))
     init = DECL_CAPTURED_VARIABLE (init);
   if (decl_constant_var_p (init))
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C
new file mode 100644
index 00000000000..e621a0d14d0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C
@@ -0,0 +1,11 @@
+// PR c++/108829
+// { dg-do compile { target c++11 } }
+
+template <int>
+void f(void) {
+  constexpr int IDX_PAGE_SIZE = 4096;
+  int abyPage = [=, abyPage] { return IDX_PAGE_SIZE; }(); // { dg-error "redundant" }
+}
+void h() {
+  f<1>();
+}

base-commit: 6245441e124846d0c3551f312d2feef598fe251c
-- 
2.39.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-02-20  9:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-17 18:58 [PATCH] c++: ICE with redundant capture [PR108829] Marek Polacek
2023-02-17 20:00 ` Patrick Palka
2023-02-17 21:06   ` [PATCH v2] " Marek Polacek
2023-02-17 21:27     ` Patrick Palka
2023-02-17 21:32       ` Patrick Palka
2023-02-17 22:42         ` [PATCH v3] " Marek Polacek
2023-02-20  2:43           ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).