public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/93842] generic lambda accesses a variable with with automatic storage duration that wasn't captured by the lambda expression
       [not found] <bug-93842-4@http.gcc.gnu.org/bugzilla/>
@ 2020-06-16 16:42 ` kuzniar95 at o2 dot pl
  2020-06-16 16:47 ` kuzniar95 at o2 dot pl
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: kuzniar95 at o2 dot pl @ 2020-06-16 16:42 UTC (permalink / raw)
  To: gcc-bugs

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

kuzniar95 at o2 dot pl changed:

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

--- Comment #5 from kuzniar95 at o2 dot pl ---
Actually everything is done well, my bad, sorry.

This code explains what's going on:

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

void not_odr_use(char);
void odr_use(char&);

int main()
{
    constexpr char ch1 = '=';

    [] { not_odr_use(ch1); }; // compiles
    [] { odr_use(ch1); }; // doesn't compile and it shouldn't



    constexpr char ch2 = '=';
    [](auto) { not_odr_use(ch2); }; // this line doesn't instantiate the
template (generic lambda is like a hidden template function) so "ch2" never
gets to be used
}

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

I'm happy to close this and confirm that it isn't a compiler bug.

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

* [Bug c++/93842] generic lambda accesses a variable with with automatic storage duration that wasn't captured by the lambda expression
       [not found] <bug-93842-4@http.gcc.gnu.org/bugzilla/>
  2020-06-16 16:42 ` [Bug c++/93842] generic lambda accesses a variable with with automatic storage duration that wasn't captured by the lambda expression kuzniar95 at o2 dot pl
@ 2020-06-16 16:47 ` kuzniar95 at o2 dot pl
  2020-06-16 17:09 ` kuzniar95 at o2 dot pl
  2020-06-16 17:20 ` kuzniar95 at o2 dot pl
  3 siblings, 0 replies; 4+ messages in thread
From: kuzniar95 at o2 dot pl @ 2020-06-16 16:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from kuzniar95 at o2 dot pl ---
P.S. odr_use function signature should be:

void odr_use(const char&);

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

* [Bug c++/93842] generic lambda accesses a variable with with automatic storage duration that wasn't captured by the lambda expression
       [not found] <bug-93842-4@http.gcc.gnu.org/bugzilla/>
  2020-06-16 16:42 ` [Bug c++/93842] generic lambda accesses a variable with with automatic storage duration that wasn't captured by the lambda expression kuzniar95 at o2 dot pl
  2020-06-16 16:47 ` kuzniar95 at o2 dot pl
@ 2020-06-16 17:09 ` kuzniar95 at o2 dot pl
  2020-06-16 17:20 ` kuzniar95 at o2 dot pl
  3 siblings, 0 replies; 4+ messages in thread
From: kuzniar95 at o2 dot pl @ 2020-06-16 17:09 UTC (permalink / raw)
  To: gcc-bugs

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

kuzniar95 at o2 dot pl changed:

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

--- Comment #7 from kuzniar95 at o2 dot pl ---
Oh, actually I'm reopening as it still incorrectly accepts code it shouldn't. I
made a wrong assumption because I incorrectly tested that using not_odr_use
function before.

So, once more:

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

void not_odr_use(char const);
void odr_use(char const&);

int main()
{
    constexpr char ch = '=';

    [] { not_odr_use(ch); }; // compiles, OK
    [] { odr_use(ch); }; // doesn't compile, OK

    [](auto) { not_odr_use(ch); }; // compiles, OK 
    [](auto) { odr_use(ch); }; // compiles, NOT OK (GCC should require lambda
capture)
}

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

Previous investigation on "-Wunused" is correct, i.e. if the user doesn't
instantiate a generic lambda's function call operator, it should be a warning.

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

* [Bug c++/93842] generic lambda accesses a variable with with automatic storage duration that wasn't captured by the lambda expression
       [not found] <bug-93842-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2020-06-16 17:09 ` kuzniar95 at o2 dot pl
@ 2020-06-16 17:20 ` kuzniar95 at o2 dot pl
  3 siblings, 0 replies; 4+ messages in thread
From: kuzniar95 at o2 dot pl @ 2020-06-16 17:20 UTC (permalink / raw)
  To: gcc-bugs

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

kuzniar95 at o2 dot pl changed:

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

--- Comment #8 from kuzniar95 at o2 dot pl ---
I've discovered that turning:

[](auto) { odr_use(ch); };

into:

[](auto) { odr_use(ch); }(123);


finally triggers a longed-for error:

------
lambda.cpp: In instantiation of ‘main()::<lambda(auto:2)> [with auto:2 = int]’:
lambda.cpp:12:34:   required from here
lambda.cpp:12:24: error: ‘ch’ is not captured
   12 |     [](auto) { odr_use(ch); }(123);
      |                        ^~
lambda.cpp:12:6: note: the lambda has no capture-default
   12 |     [](auto) { odr_use(ch); }(123);
      |      ^
lambda.cpp:6:20: note: ‘constexpr const char ch’ declared here
    6 |     constexpr char ch = '=';
      |

------

This is good enough for me so I'm closing this bug report.

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

end of thread, other threads:[~2020-06-16 17:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-93842-4@http.gcc.gnu.org/bugzilla/>
2020-06-16 16:42 ` [Bug c++/93842] generic lambda accesses a variable with with automatic storage duration that wasn't captured by the lambda expression kuzniar95 at o2 dot pl
2020-06-16 16:47 ` kuzniar95 at o2 dot pl
2020-06-16 17:09 ` kuzniar95 at o2 dot pl
2020-06-16 17:20 ` kuzniar95 at o2 dot pl

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