public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64791] New: Generic lambda fails to implicitly capture `const` variable
@ 2015-01-25 21:33 tom at kera dot name
  2015-01-25 21:36 ` [Bug c++/64791] " tom at kera dot name
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: tom at kera dot name @ 2015-01-25 21:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 64791
           Summary: Generic lambda fails to implicitly capture `const`
                    variable
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tom at kera dot name

>From http://stackoverflow.com/q/28141403/560648

Reproduction:

/////////////////////////////
#include <iostream>
#include <functional>

int main()
{
    const int a = 2;
    std::function<void(int)> f = [&](auto b) { std::cout << a << ", " << b <<
std::endl; };
    f(3);
}
/////////////////////////////


Taking any of the following steps allows the program to build and run with the
expected output "2, 3":

- remove `const` from declaration of a
- name `a` in the capture-list instead of relying on implicit capture
- change declaration of `f` from `std::function<void(int)>` to `auto`
- make the lambda non-generic by changing `auto b` to `int b`
- use Clang (e.g. v3.5.0)

Suspect detection of odr-use is breaking, or this could be related to bug
61814, or something else entirely?


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

end of thread, other threads:[~2015-02-02 13:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-25 21:33 [Bug c++/64791] New: Generic lambda fails to implicitly capture `const` variable tom at kera dot name
2015-01-25 21:36 ` [Bug c++/64791] " tom at kera dot name
2015-01-25 22:14 ` tom at kera dot name
2015-01-27 12:49 ` ville.voutilainen at gmail dot com
2015-01-27 12:53 ` ville.voutilainen at gmail dot com
2015-01-31 11:56 ` ville.voutilainen at gmail dot com
2015-01-31 12:18 ` paolo.carlini at oracle dot com
2015-02-02 13:54 ` ville.voutilainen 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).