public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112867] New: extern function declaration in function scope behaves differently in template
@ 2023-12-05 17:59 a.elovikov at gmail dot com
  2023-12-05 18:03 ` [Bug c++/112867] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: a.elovikov at gmail dot com @ 2023-12-05 17:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112867
           Summary: extern function declaration in function scope behaves
                    differently in template
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: a.elovikov at gmail dot com
  Target Milestone: ---

#ifdef GOOD
auto foo(int x)
#else
template <typename T0>
auto foo(T0 x) 
#endif
{
    return [](auto xs) {
        extern int bar(decltype(xs));
        return bar(xs);
    }(x);
}

auto test(int x) { return foo(x); }

Fails like this (no options, https://godbolt.org/z/1EGsK75bW):
<source>: In instantiation of 'foo<int>(int)::<lambda(auto:1)> [with auto:1 =
int]':
<source>:11:6:   required from 'auto foo(T0) [with T0 = int]'
    8 |     return [](auto xs) {
      |            ~~~~~~~~~~~~~
    9 |         extern int bar(decltype(xs));
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   10 |         return bar(xs);
      |         ~~~~~~~~~~~~~~~
   11 |     }(x);
      |     ~^~~
<source>:14:30:   required from here
   14 | auto test(int x) { return foo(x); }
      |                           ~~~^~~
<source>:10:19: error: 'bar' was not declared in this scope
   10 |         return bar(xs);
      |                ~~~^~~~
Compiler returned: 1

Passes with -DGOOD (https://godbolt.org/z/dn8rzGMae).

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

* [Bug c++/112867] extern function declaration in function scope behaves differently in template
  2023-12-05 17:59 [Bug c++/112867] New: extern function declaration in function scope behaves differently in template a.elovikov at gmail dot com
@ 2023-12-05 18:03 ` pinskia at gcc dot gnu.org
  2023-12-05 18:05 ` [Bug c++/112867] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-05 18:03 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

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

* [Bug c++/112867] [11/12/13/14 Regression] extern function declaration in function scope behaves differently in template
  2023-12-05 17:59 [Bug c++/112867] New: extern function declaration in function scope behaves differently in template a.elovikov at gmail dot com
  2023-12-05 18:03 ` [Bug c++/112867] " pinskia at gcc dot gnu.org
@ 2023-12-05 18:05 ` pinskia at gcc dot gnu.org
  2023-12-05 18:11 ` [Bug c++/112867] [11/12/13/14 Regression] extern function declaration inside a generic (templated) lambda inside a template function goes wrong pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-05 18:05 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|extern function declaration |[11/12/13/14 Regression]
                   |in function scope behaves   |extern function declaration
                   |differently in template     |in function scope behaves
                   |                            |differently in template
      Known to fail|                            |11.1.0
   Last reconfirmed|                            |2023-12-05
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|                            |needs-bisection
      Known to work|                            |7.5.0

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It was accepted in GCC 7.5.0 and before.
ICE between GCC 8.1.0 and GCC 10.5.0.
And rejected since GCC 11.1.0.

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

* [Bug c++/112867] [11/12/13/14 Regression] extern function declaration inside a generic (templated) lambda inside a template function goes wrong
  2023-12-05 17:59 [Bug c++/112867] New: extern function declaration in function scope behaves differently in template a.elovikov at gmail dot com
  2023-12-05 18:03 ` [Bug c++/112867] " pinskia at gcc dot gnu.org
  2023-12-05 18:05 ` [Bug c++/112867] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2023-12-05 18:11 ` pinskia at gcc dot gnu.org
  2023-12-05 18:12 ` mpolacek at gcc dot gnu.org
  2023-12-06  7:57 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-05 18:11 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |c++-lambda
            Summary|[11/12/13/14 Regression]    |[11/12/13/14 Regression]
                   |extern function declaration |extern function declaration
                   |in function scope behaves   |inside a generic
                   |differently in template     |(templated) lambda inside a
                   |                            |template function goes
                   |                            |wrong

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The extern function definition does not need to have a depedent type either.

So:
```
template <typename T0>
void foo(T0 x)
{
    [](auto xs) {
        extern void bar(int);
        return bar(xs);
    }(x);
}

void test(int x) { foo(x); }
```

is enough.

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

* [Bug c++/112867] [11/12/13/14 Regression] extern function declaration inside a generic (templated) lambda inside a template function goes wrong
  2023-12-05 17:59 [Bug c++/112867] New: extern function declaration in function scope behaves differently in template a.elovikov at gmail dot com
                   ` (2 preceding siblings ...)
  2023-12-05 18:11 ` [Bug c++/112867] [11/12/13/14 Regression] extern function declaration inside a generic (templated) lambda inside a template function goes wrong pinskia at gcc dot gnu.org
@ 2023-12-05 18:12 ` mpolacek at gcc dot gnu.org
  2023-12-06  7:57 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-12-05 18:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This worked in GCC 7.  GCC 8 started ICEing with r8-2720-gf44a8dd56f5bfb

commit f44a8dd56f5bfbd0596c39693e268ef880c06221
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Aug 29 16:37:15 2017 -0400

    Reimplement handling of lambdas in templates.

Then, the ICE was fixed by r11-3192 and the test compiled fine again:

commit e9fdb9a73249f95f3da2d7fde6f268ae12d0d22c
Author: Nathan Sidwell <nathan@acm.org>
Date:   Mon Sep 14 09:42:29 2020 -0700

    c++: local externs in templates do not get template head

and then with r11-3699:

commit 4e62aca0e0520e4ed2532f2d8153581190621c1a
Author: Nathan Sidwell <nathan@acm.org>
Date:   Wed Oct 7 05:46:24 2020 -0700

    c++: block-scope externs get an alias [PR95677,PR31775,PR95677]

the error appeared.

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

* [Bug c++/112867] [11/12/13/14 Regression] extern function declaration inside a generic (templated) lambda inside a template function goes wrong
  2023-12-05 17:59 [Bug c++/112867] New: extern function declaration in function scope behaves differently in template a.elovikov at gmail dot com
                   ` (3 preceding siblings ...)
  2023-12-05 18:12 ` mpolacek at gcc dot gnu.org
@ 2023-12-06  7:57 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-12-06  7:57 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |13.2.0
           Priority|P3                          |P2

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

end of thread, other threads:[~2023-12-06  7:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-05 17:59 [Bug c++/112867] New: extern function declaration in function scope behaves differently in template a.elovikov at gmail dot com
2023-12-05 18:03 ` [Bug c++/112867] " pinskia at gcc dot gnu.org
2023-12-05 18:05 ` [Bug c++/112867] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-12-05 18:11 ` [Bug c++/112867] [11/12/13/14 Regression] extern function declaration inside a generic (templated) lambda inside a template function goes wrong pinskia at gcc dot gnu.org
2023-12-05 18:12 ` mpolacek at gcc dot gnu.org
2023-12-06  7:57 ` rguenth 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).