public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r8-10892] c++: Fix operator() lookup in lambdas [PR95451]
@ 2021-04-22 16:51 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-04-22 16:51 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:a42f679e87e5982788981439d9d1ff2fdd7323e9
commit r8-10892-ga42f679e87e5982788981439d9d1ff2fdd7323e9
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri Feb 26 10:43:28 2021 +0100
c++: Fix operator() lookup in lambdas [PR95451]
During name lookup, name-lookup.c uses:
if (!(!iter->type && HIDDEN_TYPE_BINDING_P (iter))
&& (bool (want & LOOK_want::HIDDEN_LAMBDA)
|| !is_lambda_ignored_entity (iter->value))
&& qualify_lookup (iter->value, want))
binding = iter->value;
Unfortunately as the following testcase shows, this doesn't work in
generic lambdas, where we on the auto b = ... lambda ICE and on the
auto d = lambda reject it even when it should be valid. The problem
is that the binding doesn't have a FUNCTION_DECL with
LAMBDA_FUNCTION_P for the operator(), but an OVERLOAD with
TEMPLATE_DECL for such FUNCTION_DECL.
The following patch fixes that in is_lambda_ignored_entity, other
possibility would be to do that before calling is_lambda_ignored_entity
in name-lookup.c.
2021-02-26 Jakub Jelinek <jakub@redhat.com>
PR c++/95451
* lambda.c (is_lambda_ignored_entity): Before checking for
LAMBDA_FUNCTION_P, use OVL_FIRST. Drop FUNCTION_DECL check.
* g++.dg/cpp1y/lambda-generic-95451.C: New test.
(cherry picked from commit 8f9308936cf1df134d5aac1f890eb67266530ab5)
Diff:
---
gcc/cp/lambda.c | 3 +-
gcc/testsuite/g++.dg/cpp1y/lambda-generic-95451.C | 35 +++++++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index 292f02a4323..14f2022c0be 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -1315,7 +1315,8 @@ is_lambda_ignored_entity (tree val)
/* None of the lookups that use qualify_lookup want the op() from the
lambda; they want the one from the enclosing class. */
- if (TREE_CODE (val) == FUNCTION_DECL && LAMBDA_FUNCTION_P (val))
+ val = OVL_FIRST (val);
+ if (LAMBDA_FUNCTION_P (val))
return true;
return false;
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-95451.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-95451.C
new file mode 100644
index 00000000000..1315c01f456
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-95451.C
@@ -0,0 +1,35 @@
+// PR c++/95451
+// { dg-do run { target c++14 } }
+
+extern "C" void abort ();
+
+struct A {
+ template <typename>
+ void foo ()
+ {
+ auto b = [this] (auto) { return operator () (); } (0);
+ if (b != 3)
+ abort ();
+ auto c = [this] (int) { return operator () (); } (0);
+ if (c != 3)
+ abort ();
+ }
+ void bar ()
+ {
+ auto d = [this] (auto) { return operator () (); } (0);
+ if (d != 3)
+ abort ();
+ auto e = [this] (int) { return operator () (); } (0);
+ if (e != 3)
+ abort ();
+ }
+ int operator () () { return 3; }
+};
+
+int
+main ()
+{
+ A a;
+ a.foo<void> ();
+ a.bar ();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-22 16:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 16:51 [gcc r8-10892] c++: Fix operator() lookup in lambdas [PR95451] Jakub Jelinek
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).