public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96184] New: GCC treats "use of local variable with automatic storage from containing function" differently in versions
@ 2020-07-13 12:41 haoxintu at gmail dot com
  2020-07-29  3:27 ` [Bug c++/96184] " haoxintu at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: haoxintu at gmail dot com @ 2020-07-13 12:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96184
           Summary: GCC treats "use of local variable with automatic
                    storage from containing function" differently in
                    versions
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi, all.

This code, GCC-trunk and other versions (etc., GCC-10) treat it differently.

$cat test.cc
int main(){
    int a  = 10;
    int const b = 10;
    auto p = [ ] () noexcept ( b ? 0 : a = b) { return 0;};
    return 0;
}

$g++-trunk -std=c++14 test.cc
//nothing

$g++-10 -std=c++14 test.cc
test.cc: In function ‘int main()’:
test.cc:4:40: error: use of local variable with automatic storage from
containing function
    4 |     auto p = [ ] () noexcept ( b ? 0 : a = b) { return 0;};
      |                                        ^
test.cc:2:9: note: ‘int a’ declared here
    2 |     int a  = 10;
      |         ^

I am wondering is this a enhancement of GCC-trunk? 

I also test this in other GCC versions. Weirdly, only GCC-9 or GCC-10 rejects
it while other versions from 6.1 to 8.3 (also trunk) accepts it.

I don't know how GCC deals with this case and this also makes me confused.

Thanks,
Haoxin

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

* [Bug c++/96184] GCC treats "use of local variable with automatic storage from containing function" differently in versions
  2020-07-13 12:41 [Bug c++/96184] New: GCC treats "use of local variable with automatic storage from containing function" differently in versions haoxintu at gmail dot com
@ 2020-07-29  3:27 ` haoxintu at gmail dot com
  2020-11-04 15:49 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: haoxintu at gmail dot com @ 2020-07-29  3:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Haoxin Tu <haoxintu at gmail dot com> ---
This behavior still exists in the current trunk.

Is this a bug or not?

Thanks

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

* [Bug c++/96184] GCC treats "use of local variable with automatic storage from containing function" differently in versions
  2020-07-13 12:41 [Bug c++/96184] New: GCC treats "use of local variable with automatic storage from containing function" differently in versions haoxintu at gmail dot com
  2020-07-29  3:27 ` [Bug c++/96184] " haoxintu at gmail dot com
@ 2020-11-04 15:49 ` redi at gcc dot gnu.org
  2021-09-10  6:56 ` [Bug c++/96184] [9/10 Regression] " pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2020-11-04 15:49 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org
           Keywords|diagnostic                  |

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This was accepted until r266224 (for PR c++/52869) and then started to be
rejected, until r11-289 (for PR c++/90748). I don't think either of them
intended to change this specific case.

EDG rejects it, but Clang also accepts it.

I have no idea if it's valid.

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

* [Bug c++/96184] [9/10 Regression] GCC treats "use of local variable with automatic storage from containing function" differently in versions
  2020-07-13 12:41 [Bug c++/96184] New: GCC treats "use of local variable with automatic storage from containing function" differently in versions haoxintu at gmail dot com
  2020-07-29  3:27 ` [Bug c++/96184] " haoxintu at gmail dot com
  2020-11-04 15:49 ` redi at gcc dot gnu.org
@ 2021-09-10  6:56 ` pinskia at gcc dot gnu.org
  2021-09-10 20:05 ` [Bug c++/96184] [11/12 " jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-10  6:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |rejects-valid
     Ever confirmed|0                           |1
            Summary|GCC treats "use of local    |[9/10 Regression] GCC
                   |variable with automatic     |treats "use of local
                   |storage from containing     |variable with automatic
                   |function" differently in    |storage from containing
                   |versions                    |function" differently in
                   |                            |versions
   Target Milestone|---                         |9.5
   Last reconfirmed|                            |2021-09-10

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So I think it is legal because if we have:


int main(){
    int a  = 10;
    int const b = 10;
    static constexpr int d = b ? 0 : a = b;
    auto p1 = [ ] () noexcept ( d) { return d;};
    return d;
}

the d is a constexpr at this point and a valid one and was even accepted before
in GCC 8.5.0.

So this is only a regression in GCC 9 and GCC 10.

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

* [Bug c++/96184] [11/12 Regression] GCC treats "use of local variable with automatic storage from containing function" differently in versions
  2020-07-13 12:41 [Bug c++/96184] New: GCC treats "use of local variable with automatic storage from containing function" differently in versions haoxintu at gmail dot com
                   ` (2 preceding siblings ...)
  2021-09-10  6:56 ` [Bug c++/96184] [9/10 Regression] " pinskia at gcc dot gnu.org
@ 2021-09-10 20:05 ` jason at gcc dot gnu.org
  2021-09-13  2:48 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2021-09-10 20:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
   Target Milestone|9.5                         |11.0
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
            Summary|[9/10 Regression] GCC       |[11/12 Regression] GCC
                   |treats "use of local        |treats "use of local
                   |variable with automatic     |variable with automatic
                   |storage from containing     |storage from containing
                   |function" differently in    |function" differently in
                   |versions                    |versions

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
I think it's ill-formed, because the use of 'a' is in a function parameter
scope, rather than in 'main'.

The changes in whether we accepted this testcase were indeed by accident, as
the way we handled 'this' injection changed whether parsing_nsdmi() returned
true.

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

* [Bug c++/96184] [11/12 Regression] GCC treats "use of local variable with automatic storage from containing function" differently in versions
  2020-07-13 12:41 [Bug c++/96184] New: GCC treats "use of local variable with automatic storage from containing function" differently in versions haoxintu at gmail dot com
                   ` (3 preceding siblings ...)
  2021-09-10 20:05 ` [Bug c++/96184] [11/12 " jason at gcc dot gnu.org
@ 2021-09-13  2:48 ` jason at gcc dot gnu.org
  2021-09-13  2:50 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2021-09-13  2:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Created attachment 51446
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51446&action=edit
fix that causes regressions

This patch fixes this testcase, but regresses the testcases from PR91506 and
PR41786 due to giving the error during tentative parsing, before the tentative
parse fails and we parse the statement again as a (well-formed) expression. 
Addressing that would be a lot more work than this obscure borderline bug
merits.

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

* [Bug c++/96184] [11/12 Regression] GCC treats "use of local variable with automatic storage from containing function" differently in versions
  2020-07-13 12:41 [Bug c++/96184] New: GCC treats "use of local variable with automatic storage from containing function" differently in versions haoxintu at gmail dot com
                   ` (4 preceding siblings ...)
  2021-09-13  2:48 ` jason at gcc dot gnu.org
@ 2021-09-13  2:50 ` jason at gcc dot gnu.org
  2022-01-08 10:46 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2021-09-13  2:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|jason at gcc dot gnu.org           |unassigned at gcc dot gnu.org
             Status|ASSIGNED                    |NEW
           Keywords|rejects-valid               |accepts-invalid

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

* [Bug c++/96184] [11/12 Regression] GCC treats "use of local variable with automatic storage from containing function" differently in versions
  2020-07-13 12:41 [Bug c++/96184] New: GCC treats "use of local variable with automatic storage from containing function" differently in versions haoxintu at gmail dot com
                   ` (5 preceding siblings ...)
  2021-09-13  2:50 ` jason at gcc dot gnu.org
@ 2022-01-08 10:46 ` pinskia at gcc dot gnu.org
  2022-04-21  7:48 ` rguenth at gcc dot gnu.org
  2023-05-29 10:03 ` [Bug c++/96184] [11/12/13/14 " jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-08 10:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.0                        |11.3

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

* [Bug c++/96184] [11/12 Regression] GCC treats "use of local variable with automatic storage from containing function" differently in versions
  2020-07-13 12:41 [Bug c++/96184] New: GCC treats "use of local variable with automatic storage from containing function" differently in versions haoxintu at gmail dot com
                   ` (6 preceding siblings ...)
  2022-01-08 10:46 ` pinskia at gcc dot gnu.org
@ 2022-04-21  7:48 ` rguenth at gcc dot gnu.org
  2023-05-29 10:03 ` [Bug c++/96184] [11/12/13/14 " jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-21  7:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.3                        |11.4

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.3 is being released, retargeting bugs to GCC 11.4.

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

* [Bug c++/96184] [11/12/13/14 Regression] GCC treats "use of local variable with automatic storage from containing function" differently in versions
  2020-07-13 12:41 [Bug c++/96184] New: GCC treats "use of local variable with automatic storage from containing function" differently in versions haoxintu at gmail dot com
                   ` (7 preceding siblings ...)
  2022-04-21  7:48 ` rguenth at gcc dot gnu.org
@ 2023-05-29 10:03 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-29 10:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 11.4 is being released, retargeting bugs to GCC 11.5.

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

end of thread, other threads:[~2023-05-29 10:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-13 12:41 [Bug c++/96184] New: GCC treats "use of local variable with automatic storage from containing function" differently in versions haoxintu at gmail dot com
2020-07-29  3:27 ` [Bug c++/96184] " haoxintu at gmail dot com
2020-11-04 15:49 ` redi at gcc dot gnu.org
2021-09-10  6:56 ` [Bug c++/96184] [9/10 Regression] " pinskia at gcc dot gnu.org
2021-09-10 20:05 ` [Bug c++/96184] [11/12 " jason at gcc dot gnu.org
2021-09-13  2:48 ` jason at gcc dot gnu.org
2021-09-13  2:50 ` jason at gcc dot gnu.org
2022-01-08 10:46 ` pinskia at gcc dot gnu.org
2022-04-21  7:48 ` rguenth at gcc dot gnu.org
2023-05-29 10:03 ` [Bug c++/96184] [11/12/13/14 " jakub 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).