public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope
@ 2020-09-27 17:37 hstong at ca dot ibm.com
  2020-09-27 20:51 ` [Bug c++/97219] " nathan at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: hstong at ca dot ibm.com @ 2020-09-27 17:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219

            Bug ID: 97219
           Summary: Generic lambda does not find function declaration from
                    enclosing block scope
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid, rejects-valid, wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hstong at ca dot ibm.com
  Target Milestone: ---

The unqualified lookup for `q` in the instantiation of the generic lambda
should resolve to the block-scope function declaration.
Such a lookup result should furthermore suppress argument dependent lookup.

GCC resolves `q` using argument dependent lookup at the point of instantiation
and chooses a worse candidate.

### SOURCE (<stdin>):
struct B;

template <typename T>
auto f(T *) {
  void q(B *, void * = static_cast<T *>(0));
  return [](auto *p) { q(p); };
}

void q(void *) = delete;

int main(void) {
  B *bp = 0;
  f(bp)(bp);
}


### COMPILER INVOCATION:
g++ -fsyntax-only -std=c++20 -Wall -Wextra -pedantic-errors -xc++ -


### ACTUAL OUTPUT:
<stdin>: In instantiation of 'f<B>::<lambda(auto:1*)> [with auto:1 = B]':
<stdin>:13:11:   required from here
<stdin>:6:25: error: use of deleted function 'void q(void*)'
<stdin>:9:6: note: declared here


### EXPECTED OUTPUT:
(clean compile)


### COMPILER VERSION INFO (g++ -v):
Using built-in specs.
COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++
COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head
--enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl
--enable-checking=release --disable-nls --enable-lto
LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20200925 (experimental) (GCC)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/97219] Generic lambda does not find function declaration from enclosing block scope
  2020-09-27 17:37 [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope hstong at ca dot ibm.com
@ 2020-09-27 20:51 ` nathan at gcc dot gnu.org
  2021-11-29 21:12 ` [Bug c++/97219] [9/10/11/12 Regression] " ppalka at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: nathan at gcc dot gnu.org @ 2020-09-27 20:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219

Nathan Sidwell <nathan at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |nathan at gcc dot gnu.org
                 CC|                            |nathan at gcc dot gnu.org

--- Comment #1 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
ah, another local extern decl thing

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/97219] [9/10/11/12 Regression] Generic lambda does not find function declaration from enclosing block scope
  2020-09-27 17:37 [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope hstong at ca dot ibm.com
  2020-09-27 20:51 ` [Bug c++/97219] " nathan at gcc dot gnu.org
@ 2021-11-29 21:12 ` ppalka at gcc dot gnu.org
  2021-11-29 21:13 ` ppalka at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-11-29 21:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-11-29
     Ever confirmed|0                           |1
                 CC|                            |ppalka at gcc dot gnu.org
            Summary|Generic lambda does not     |[9/10/11/12 Regression]
                   |find function declaration   |Generic lambda does not
                   |from enclosing block scope  |find function declaration
                   |                            |from enclosing block scope
   Target Milestone|---                         |9.5
             Status|UNCONFIRMED                 |NEW
      Known to work|                            |7.1.0
      Known to fail|                            |10.3.0, 11.2.0, 12.0, 9.4.0

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Started with r8-1010.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/97219] [9/10/11/12 Regression] Generic lambda does not find function declaration from enclosing block scope
  2020-09-27 17:37 [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope hstong at ca dot ibm.com
  2020-09-27 20:51 ` [Bug c++/97219] " nathan at gcc dot gnu.org
  2021-11-29 21:12 ` [Bug c++/97219] [9/10/11/12 Regression] " ppalka at gcc dot gnu.org
@ 2021-11-29 21:13 ` ppalka at gcc dot gnu.org
  2022-01-17 15:06 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-11-29 21:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Related testcase:

void f() {
  extern void g();
  [] (auto) { g(); }(0);
}

We started rejecting this one with r8-7277.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/97219] [9/10/11/12 Regression] Generic lambda does not find function declaration from enclosing block scope
  2020-09-27 17:37 [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope hstong at ca dot ibm.com
                   ` (2 preceding siblings ...)
  2021-11-29 21:13 ` ppalka at gcc dot gnu.org
@ 2022-01-17 15:06 ` rguenth at gcc dot gnu.org
  2022-04-14  0:25 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-17 15:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/97219] [9/10/11/12 Regression] Generic lambda does not find function declaration from enclosing block scope
  2020-09-27 17:37 [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope hstong at ca dot ibm.com
                   ` (3 preceding siblings ...)
  2022-01-17 15:06 ` rguenth at gcc dot gnu.org
@ 2022-04-14  0:25 ` cvs-commit at gcc dot gnu.org
  2022-04-14  0:25 ` [Bug c++/97219] [9/10/11 " jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-04-14  0:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:1824da60663b4532199ecd051d8ba6da8995821d

commit r12-8152-g1824da60663b4532199ecd051d8ba6da8995821d
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 13 16:42:25 2022 -0400

    c++: local fn and generic lambda [PR97219]

    When instantiating the op() for a generic lambda, we can no longer do name
    lookup inside function scopes enclosing the lambda, so we need to remember
    the lookup result from processing the definition of the lambda.  So the
code
    in finish_call_expr to throw away the lookup result and instead look it up
    again at instantiation time needs to be adjusted.  The approach I take is
to
    only discard the result if the local extern comes from dependent scope;
once
    the enclosing function template is instantiated and we're regenerating the
    lambda, then we can remember the result of lookup.  We also need any
default
    arguments to be instantiated at that point.

            PR c++/97219

    gcc/cp/ChangeLog:

            * name-lookup.cc (dependent_local_decl_p): New.
            * cp-tree.h (dependent_local_decl_p): Declare.
            * semantics.cc (finish_call_expr): Use it.
            * pt.cc (tsubst_arg_types): Also substitute default args
            for local externs.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/lambda-generic-local-fn1.C: New test.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/97219] [9/10/11 Regression] Generic lambda does not find function declaration from enclosing block scope
  2020-09-27 17:37 [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope hstong at ca dot ibm.com
                   ` (4 preceding siblings ...)
  2022-04-14  0:25 ` cvs-commit at gcc dot gnu.org
@ 2022-04-14  0:25 ` jason at gcc dot gnu.org
  2022-05-27  9:43 ` [Bug c++/97219] [10/11 " rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2022-04-14  0:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |12.0
             Status|NEW                         |ASSIGNED
           Assignee|nathan at gcc dot gnu.org          |jason at gcc dot gnu.org
      Known to fail|12.0                        |
            Summary|[9/10/11/12 Regression]     |[9/10/11 Regression]
                   |Generic lambda does not     |Generic lambda does not
                   |find function declaration   |find function declaration
                   |from enclosing block scope  |from enclosing block scope

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/97219] [10/11 Regression] Generic lambda does not find function declaration from enclosing block scope
  2020-09-27 17:37 [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope hstong at ca dot ibm.com
                   ` (5 preceding siblings ...)
  2022-04-14  0:25 ` [Bug c++/97219] [9/10/11 " jason at gcc dot gnu.org
@ 2022-05-27  9:43 ` rguenth at gcc dot gnu.org
  2022-06-28 10:42 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27  9:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.5                         |10.4

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/97219] [10/11 Regression] Generic lambda does not find function declaration from enclosing block scope
  2020-09-27 17:37 [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope hstong at ca dot ibm.com
                   ` (6 preceding siblings ...)
  2022-05-27  9:43 ` [Bug c++/97219] [10/11 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:42 ` jakub at gcc dot gnu.org
  2023-07-07 10:38 ` [Bug c++/97219] [11 " rguenth at gcc dot gnu.org
  2023-12-19 21:56 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |10.5

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/97219] [11 Regression] Generic lambda does not find function declaration from enclosing block scope
  2020-09-27 17:37 [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope hstong at ca dot ibm.com
                   ` (7 preceding siblings ...)
  2022-06-28 10:42 ` jakub at gcc dot gnu.org
@ 2023-07-07 10:38 ` rguenth at gcc dot gnu.org
  2023-12-19 21:56 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/97219] [11 Regression] Generic lambda does not find function declaration from enclosing block scope
  2020-09-27 17:37 [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope hstong at ca dot ibm.com
                   ` (8 preceding siblings ...)
  2023-07-07 10:38 ` [Bug c++/97219] [11 " rguenth at gcc dot gnu.org
@ 2023-12-19 21:56 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2023-12-19 21:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97219

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|11.5                        |12.0

--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 12, backporting seems too complicated.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-12-19 21:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-27 17:37 [Bug c++/97219] New: Generic lambda does not find function declaration from enclosing block scope hstong at ca dot ibm.com
2020-09-27 20:51 ` [Bug c++/97219] " nathan at gcc dot gnu.org
2021-11-29 21:12 ` [Bug c++/97219] [9/10/11/12 Regression] " ppalka at gcc dot gnu.org
2021-11-29 21:13 ` ppalka at gcc dot gnu.org
2022-01-17 15:06 ` rguenth at gcc dot gnu.org
2022-04-14  0:25 ` cvs-commit at gcc dot gnu.org
2022-04-14  0:25 ` [Bug c++/97219] [9/10/11 " jason at gcc dot gnu.org
2022-05-27  9:43 ` [Bug c++/97219] [10/11 " rguenth at gcc dot gnu.org
2022-06-28 10:42 ` jakub at gcc dot gnu.org
2023-07-07 10:38 ` [Bug c++/97219] [11 " rguenth at gcc dot gnu.org
2023-12-19 21:56 ` jason at gcc dot gnu.org

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).