From 4a136a214ede91ef05caac017814b142883dc80d Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 5 Feb 2020 12:53:06 -0500 Subject: [PATCH] c++: Fix ICE with lambda in operator function [PR93597] 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 | 5 +++++ gcc/cp/name-lookup.c | 8 ++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-93597.C | 8 ++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-93597.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6a7ba564d12..1c8af804b63 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2020-02-06 Marek Polacek + + 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 PR c++/93140 diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 2447166a444..2a9bae53162 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d0955e039b5..601bc336290 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-02-06 Marek Polacek + + PR c++/93597 - ICE with lambda in operator function. + * g++.dg/cpp0x/lambda/lambda-93597.C: New test. + 2020-02-06 Tobias Burnus * 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 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 +struct S { + using T ::operator<; + void operator==(T x) { [x] { 0 < x; }; } +}; -- 2.30.2