public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106552] New: GCC accepts invalid redefinition of captured variable inside lambda
@ 2022-08-08  7:59 jlame646 at gmail dot com
  2022-08-08 16:17 ` [Bug c++/106552] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jlame646 at gmail dot com @ 2022-08-08  7:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106552
           Summary: GCC accepts invalid redefinition of captured variable
                    inside lambda
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlame646 at gmail dot com
  Target Milestone: ---

The following invalid(afaik) program is accepted by gcc:
https://godbolt.org/z/sPozd36oY 

int main() {
    int x = 100;
    auto lamb_var = [y = x](){
                    int y = 10; //this is accepted by gcc even though this is a
redefinition of y
                    return y + 1;
    }; 

    assert (lamb_var() == 11);

    return 0; 
}



--------------

In the above program, since we've used `y = x`, this means the non-static data
member will be named `y` and is considered to be in the declarative region of
the lambda expression's compound statement which in turn means that the
statement int y = 10; should produced redefinition error because we're defining
a variable named `y` for the second time in the same region.

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

* [Bug c++/106552] GCC accepts invalid redefinition of captured variable inside lambda
  2022-08-08  7:59 [Bug c++/106552] New: GCC accepts invalid redefinition of captured variable inside lambda jlame646 at gmail dot com
@ 2022-08-08 16:17 ` pinskia at gcc dot gnu.org
  2022-08-08 16:33 ` pinskia at gcc dot gnu.org
  2022-08-08 19:28 ` jlame646 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-08 16:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang is the only compiler I tried which rejects this ...
ICC, MSVC all accept this code.

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

* [Bug c++/106552] GCC accepts invalid redefinition of captured variable inside lambda
  2022-08-08  7:59 [Bug c++/106552] New: GCC accepts invalid redefinition of captured variable inside lambda jlame646 at gmail dot com
  2022-08-08 16:17 ` [Bug c++/106552] " pinskia at gcc dot gnu.org
@ 2022-08-08 16:33 ` pinskia at gcc dot gnu.org
  2022-08-08 19:28 ` jlame646 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-08 16:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
expr.prim.lambda.capture/6 seems to imply this is invalid code.
But the example is only with the parameter rather than a local variable ...

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

* [Bug c++/106552] GCC accepts invalid redefinition of captured variable inside lambda
  2022-08-08  7:59 [Bug c++/106552] New: GCC accepts invalid redefinition of captured variable inside lambda jlame646 at gmail dot com
  2022-08-08 16:17 ` [Bug c++/106552] " pinskia at gcc dot gnu.org
  2022-08-08 16:33 ` pinskia at gcc dot gnu.org
@ 2022-08-08 19:28 ` jlame646 at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jlame646 at gmail dot com @ 2022-08-08 19:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jason Liam <jlame646 at gmail dot com> ---
Yes, msvc also accepts this but msvc also emits a diagnostic with the
flag *std:c++20
/W4 .*

On Mon, 8 Aug 2022, 22:03 pinskia at gcc dot gnu.org, <
gcc-bugzilla@gcc.gnu.org> wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106552
>
> --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> expr.prim.lambda.capture/6 seems to imply this is invalid code.
> But the example is only with the parameter rather than a local variable ...
>
> --
> You are receiving this mail because:
> You reported the bug.

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

end of thread, other threads:[~2022-08-08 19:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-08  7:59 [Bug c++/106552] New: GCC accepts invalid redefinition of captured variable inside lambda jlame646 at gmail dot com
2022-08-08 16:17 ` [Bug c++/106552] " pinskia at gcc dot gnu.org
2022-08-08 16:33 ` pinskia at gcc dot gnu.org
2022-08-08 19:28 ` jlame646 at gmail dot com

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