public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Fix ICE with lambda in operator function [PR93597]
@ 2020-02-05 21:31 Marek Polacek
  2020-02-05 21:40 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2020-02-05 21:31 UTC (permalink / raw)
  To: Jason Merrill, GCC Patches

If we are going to use get_first_fn let's make sure we operate
on is_overloaded_fn, as the rest of the codebase does.

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

	PR c++/93597 - ICE with lambda in operator function.
	* name-lookup.c (maybe_save_operator_binding): Check is_overloaded_fn.

	* g++.dg/cpp0x/lambda/lambda-93597.C: New test.
---
 gcc/cp/name-lookup.c                             | 13 ++++++++-----
 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-93597.C |  8 ++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-93597.C

diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 2447166a444..aa539926332 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -7624,11 +7624,14 @@ maybe_save_operator_binding (tree e)
 
   if (!fns && (fns = op_unqualified_lookup (fnname)))
     {
-      tree fn = get_first_fn (fns);
-      if (DECL_CLASS_SCOPE_P (fn))
-	/* We don't need to remember class-scope functions, normal unqualified
-	   lookup will find them again.  */
-	return;
+      if (is_overloaded_fn (fns))
+	{
+	  tree fn = get_first_fn (fns);
+	  if (DECL_CLASS_SCOPE_P (fn))
+	    /* We don't need to remember class-scope functions, normal
+	       unqualified lookup will find them again.  */
+	    return;
+	}
 
       bindings = tree_cons (fnname, fns, bindings);
       if (attr)
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-93597.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-93597.C
new file mode 100644
index 00000000000..257d9c7cdfd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-93597.C
@@ -0,0 +1,8 @@
+// PR c++/93597 - ICE with lambda in operator function.
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+struct S {
+  using T ::operator<;
+  void operator==(T x) { [x] { 0 < x; }; }
+};

base-commit: fa0c6e297b22d5883857d0db4a6a8be0967cb16f
-- 
Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA

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

end of thread, other threads:[~2020-02-06  2:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-05 21:31 [PATCH] c++: Fix ICE with lambda in operator function [PR93597] Marek Polacek
2020-02-05 21:40 ` Jason Merrill
2020-02-05 22:04   ` [PATCH v2] " Marek Polacek
2020-02-06  2:55     ` 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).