public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106412] New: Code initializing static variables with local variables compiles without errors or warnings
@ 2022-07-22 14:08 menkaur at gmail dot com
  2022-07-22 14:39 ` [Bug c++/106412] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: menkaur at gmail dot com @ 2022-07-22 14:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106412
           Summary: Code initializing static variables with local
                    variables compiles without errors or warnings
           Product: gcc
           Version: og11 (devel/omp/gcc-11)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: menkaur at gmail dot com
  Target Milestone: ---

Created attachment 53337
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53337&action=edit
minimal code example

Following code will compile without errors or warnings:


 int main(int argc, char **argv) {
       int i = 0, j = 0;
       static const auto s = i + j;
       return 0;
  }


The bug was found in gcc 12.1.0 on arch linux

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

* [Bug c++/106412] Code initializing static variables with local variables compiles without errors or warnings
  2022-07-22 14:08 [Bug c++/106412] New: Code initializing static variables with local variables compiles without errors or warnings menkaur at gmail dot com
@ 2022-07-22 14:39 ` redi at gcc dot gnu.org
  2022-07-22 15:08 ` menkaur at gmail dot com
  2022-07-22 15:28 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-22 14:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-07-22
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Arsen Zahray from comment #0)
> Following code will compile without errors or warnings:

Not true, there's a -Wunused-variable warning.

> The bug was found in gcc 12.1.0 on arch linux

Why do you think it's a bug? The code is valid.

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

* [Bug c++/106412] Code initializing static variables with local variables compiles without errors or warnings
  2022-07-22 14:08 [Bug c++/106412] New: Code initializing static variables with local variables compiles without errors or warnings menkaur at gmail dot com
  2022-07-22 14:39 ` [Bug c++/106412] " redi at gcc dot gnu.org
@ 2022-07-22 15:08 ` menkaur at gmail dot com
  2022-07-22 15:28 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: menkaur at gmail dot com @ 2022-07-22 15:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Arsen Zahray <menkaur at gmail dot com> ---
> Why do you think it's a bug? The code is valid.
The bug I made with a code like this was that I first declared a static
const variable and used it in the program, later on I added local variables
on which the variable would depend, and I forgot to remove the static
modifier, which caused the variable to always have the same value. Static
variable is supposed to be initialized before local variables on the first
call to the function, and to me it seems that using local variables to
initialize it does not make any logical sense and is bug prone

On Fri, Jul 22, 2022 at 2:39 PM redi at gcc dot gnu.org <
gcc-bugzilla@gcc.gnu.org> wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106412
>
> Jonathan Wakely <redi at gcc dot gnu.org> changed:
>
>            What    |Removed                     |Added
>
> ----------------------------------------------------------------------------
>    Last reconfirmed|                            |2022-07-22
>              Status|UNCONFIRMED                 |WAITING
>      Ever confirmed|0                           |1
>
> --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> (In reply to Arsen Zahray from comment #0)
> > Following code will compile without errors or warnings:
>
> Not true, there's a -Wunused-variable warning.
>
> > The bug was found in gcc 12.1.0 on arch linux
>
> Why do you think it's a bug? The code is valid.
>
> --
> You are receiving this mail because:
> You reported the bug.

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

* [Bug c++/106412] Code initializing static variables with local variables compiles without errors or warnings
  2022-07-22 14:08 [Bug c++/106412] New: Code initializing static variables with local variables compiles without errors or warnings menkaur at gmail dot com
  2022-07-22 14:39 ` [Bug c++/106412] " redi at gcc dot gnu.org
  2022-07-22 15:08 ` menkaur at gmail dot com
@ 2022-07-22 15:28 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-22 15:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|WAITING                     |RESOLVED

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Arsen Zahray from comment #2)
> Static
> variable is supposed to be initialized before local variables on the first
> call to the function

No, that's not true. It's initialized when control flow reaches it. If that is
after some local variables, then that's what happens.

This is not a bug.

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

end of thread, other threads:[~2022-07-22 15:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-22 14:08 [Bug c++/106412] New: Code initializing static variables with local variables compiles without errors or warnings menkaur at gmail dot com
2022-07-22 14:39 ` [Bug c++/106412] " redi at gcc dot gnu.org
2022-07-22 15:08 ` menkaur at gmail dot com
2022-07-22 15:28 ` redi 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).