]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix ICE with lambda in operator function [PR93597]
authorMarek Polacek <polacek@redhat.com>
Wed, 5 Feb 2020 17:53:06 +0000 (12:53 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 6 Feb 2020 16:58:23 +0000 (11:58 -0500)
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 6a7ba564d1280a03e82539355bffab8cd4037a05..1c8af804b63aed18df9a8d861f367c1b9ead27f6 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-06  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/93597 - ICE with lambda in operator function.
+       * name-lookup.c (maybe_save_operator_binding): Check is_overloaded_fn.
+
 2020-02-05  Jason Merrill  <jason@redhat.com>
 
        PR c++/93140
index 2447166a444150755e9cf908abceb906316edaa4..2a9bae531627eedb6579038b5c4e2ddcdfe5a044 100644 (file)
@@ -7624,10 +7624,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 d0955e039b51c99391460d7d71eac4d8b5a8e468..601bc336290b4a3da56b92c8f4a26634e3b4f9c2 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-06  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/93597 - ICE with lambda in operator function.
+       * g++.dg/cpp0x/lambda/lambda-93597.C: New test.
+
 2020-02-06  Tobias Burnus  <tobias@codesourcery.com>
 
        * gcc.target/arm/multilib.exp (multilib_config): Pass flags to
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; }; }
+};