]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix ICE with lambda in operator function [PR93597]
authorMarek Polacek <polacek@redhat.com>
Mon, 6 Apr 2020 00:31:56 +0000 (20:31 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 6 Apr 2020 00:35:26 +0000 (20:35 -0400)
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, and if lookup finds
any class-scope declaration, return early too.

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/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-93597.C [new file with mode: 0644]

index 5c49b2c67e8811326f1d151102cbd28b656e2911..2e247069b96294eedbf903b35b29520fc0a279c0 100644 (file)
@@ -1,3 +1,11 @@
+2020-04-05  Marek Polacek  <polacek@redhat.com>
+
+       2020-02-06  Marek Polacek  <polacek@redhat.com>
+       Backport from mainline
+
+       PR c++/93597 - ICE with lambda in operator function.
+       * name-lookup.c (maybe_save_operator_binding): Check is_overloaded_fn.
+
 2020-04-04  Jason Merrill  <jason@redhat.com>
 
        PR c++/91377
index 8298ee171e0aa344151fad9a9ab88af09a45c82c..f5535ba50bc017d74dccdf8054629e7e0b38f184 100644 (file)
@@ -7627,10 +7627,10 @@ 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.  */
+      tree d = is_overloaded_fn (fns) ? get_first_fn (fns) : fns;
+      if (DECL_P (d) && DECL_CLASS_SCOPE_P (d))
+       /* We don't need to remember class-scope functions or declarations,
+          normal unqualified lookup will find them again.  */
        return;
 
       bindings = tree_cons (fnname, fns, bindings);
index a1101ae50b5d8a10848d2f919d41da22fd5f0db3..ab5f3b16775575275fc710c56273c96ad021c545 100644 (file)
@@ -1,3 +1,11 @@
+2020-04-05  Marek Polacek  <polacek@redhat.com>
+
+       2020-02-06  Marek Polacek  <polacek@redhat.com>
+       Backport from mainline
+
+       PR c++/93597 - ICE with lambda in operator function.
+       * g++.dg/cpp0x/lambda/lambda-93597.C: New test.
+
 2020-04-02  Martin Jambor  <mjambor@suse.cz>
 
        PR tree-optimization/93435
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 (file)
index 0000000..257d9c7
--- /dev/null
@@ -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; }; }
+};