public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: Jason Merrill <jason@redhat.com>,	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] c++: Fix ICE with lambda in operator function [PR93597]
Date: Wed, 05 Feb 2020 21:31:00 -0000	[thread overview]
Message-ID: <20200205213103.2340184-1-polacek@redhat.com> (raw)

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

             reply	other threads:[~2020-02-05 21:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-05 21:31 Marek Polacek [this message]
2020-02-05 21:40 ` Jason Merrill
2020-02-05 22:04   ` [PATCH v2] " Marek Polacek
2020-02-06  2:55     ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200205213103.2340184-1-polacek@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).