public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54328] New: capture pointer by value is not correct
@ 2012-08-20  6:56 yaoyuan1216 at gmail dot com
  2012-08-20  7:24 ` [Bug c++/54328] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: yaoyuan1216 at gmail dot com @ 2012-08-20  6:56 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54328

             Bug #: 54328
           Summary: capture pointer by value is not correct
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: yaoyuan1216@gmail.com


int a[1];
a[0] = 1;
auto fun = [a]{cout<<a[0]<<endl;};
fun();
a[0] = 2;
fun();

This will produce:
1
1

I think it shoud be:
1
2

g++ -std=c++0x -v -save-temps -Wall t.cpp outputs:

使用内建 specs。
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/mww/.gcc/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
目标:x86_64-unknown-linux-gnu
配置为:../gcc-trunk/configure --disable-multilib --enable-checking=release
--enable-languages=c,c++ --enable-threads=posix --prefix=/home/mww/.gcc
线程模型:posix
gcc 版本 4.8.0 20120816 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-std=c++11' '-v' '-save-temps' '-Wall' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /home/mww/.gcc/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/cc1plus -E -quiet -v
-D_GNU_SOURCE t.cpp -mtune=generic -march=x86-64 -std=c++11 -Wall
-fpch-preprocess -o t.ii
忽略不存在的目录“/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../../../x86_64-unknown-linux-gnu/include”
#include "..." 搜索从这里开始:
#include <...> 搜索从这里开始:

/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../../../include/c++/4.8.0

/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../../../include/c++/4.8.0/x86_64-unknown-linux-gnu

/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../../../include/c++/4.8.0/backward
 /home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/include
 /usr/local/include
 /home/mww/.gcc/include
 /home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/include-fixed
 /usr/include
搜索列表结束。
COLLECT_GCC_OPTIONS='-std=c++11' '-v' '-save-temps' '-Wall' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /home/mww/.gcc/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/cc1plus
-fpreprocessed t.ii -quiet -dumpbase t.cpp -mtune=generic -march=x86-64
-auxbase t -Wall -std=c++11 -version -o t.s
GNU C++ (GCC) 版本 4.8.0 20120816 (experimental) (x86_64-unknown-linux-gnu)
    由 GNU C 版本 4.8.0 20120816 (experimental) 编译, GMP version 5.0.5, MPFR
version 3.1.1, MPC version 0.9
GGC 准则:--param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (GCC) 版本 4.8.0 20120816 (experimental) (x86_64-unknown-linux-gnu)
    由 GNU C 版本 4.8.0 20120816 (experimental) 编译, GMP version 5.0.5, MPFR
version 3.1.1, MPC version 0.9
GGC 准则:--param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 68a842c32ece7e9b3774793c3488162d
t.cpp: 在函数‘int main(int, const char**)’中:
t.cpp:7:6: 警告: variable ‘a’ set but not used [-Wunused-but-set-variable]
  int a[1];
      ^
COLLECT_GCC_OPTIONS='-std=c++11' '-v' '-save-temps' '-Wall' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 as -v --64 -o t.o t.s
GNU assembler version 2.20.1 (x86_64-linux-gnu) using BFD version (GNU Binutils
for Ubuntu) 2.20.1-system.20100303
COMPILER_PATH=/home/mww/.gcc/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/:/home/mww/.gcc/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/:/home/mww/.gcc/libexec/gcc/x86_64-unknown-linux-gnu/:/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/:/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/:/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-std=c++11' '-v' '-save-temps' '-Wall' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /home/mww/.gcc/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/collect2
--eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
/usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o
/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/crtbegin.o
-L/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0
-L/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../../../lib64
-L/lib/../lib64 -L/usr/lib/../lib64
-L/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../.. t.o -lstdc++
-lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/home/mww/.gcc/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/crtend.o
/usr/lib/../lib64/crtn.o


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

* [Bug c++/54328] capture pointer by value is not correct
  2012-08-20  6:56 [Bug c++/54328] New: capture pointer by value is not correct yaoyuan1216 at gmail dot com
@ 2012-08-20  7:24 ` redi at gcc dot gnu.org
  2012-08-20  7:38 ` yaoyuan1216 at gmail dot com
  2012-08-20  7:45 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2012-08-20  7:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54328

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-08-20 07:24:38 UTC ---
'a' isn't a pointer, it's an array, so the closure has a copy of the array and
a[0] = 2 doesn't alter the closure's copy.


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

* [Bug c++/54328] capture pointer by value is not correct
  2012-08-20  6:56 [Bug c++/54328] New: capture pointer by value is not correct yaoyuan1216 at gmail dot com
  2012-08-20  7:24 ` [Bug c++/54328] " redi at gcc dot gnu.org
@ 2012-08-20  7:38 ` yaoyuan1216 at gmail dot com
  2012-08-20  7:45 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: yaoyuan1216 at gmail dot com @ 2012-08-20  7:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54328

--- Comment #2 from yaoyuan1216 at gmail dot com 2012-08-20 07:38:18 UTC ---
(In reply to comment #1)
> 'a' isn't a pointer, it's an array, so the closure has a copy of the array and
> a[0] = 2 doesn't alter the closure's copy.

Thanks for your reply. You are absolutely right and I'm glad that it is my
mistake instead of gcc.


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

* [Bug c++/54328] capture pointer by value is not correct
  2012-08-20  6:56 [Bug c++/54328] New: capture pointer by value is not correct yaoyuan1216 at gmail dot com
  2012-08-20  7:24 ` [Bug c++/54328] " redi at gcc dot gnu.org
  2012-08-20  7:38 ` yaoyuan1216 at gmail dot com
@ 2012-08-20  7:45 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-08-20  7:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54328

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|                            |INVALID

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-08-20 07:45:21 UTC ---
Invalid then.


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

end of thread, other threads:[~2012-08-20  7:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-20  6:56 [Bug c++/54328] New: capture pointer by value is not correct yaoyuan1216 at gmail dot com
2012-08-20  7:24 ` [Bug c++/54328] " redi at gcc dot gnu.org
2012-08-20  7:38 ` yaoyuan1216 at gmail dot com
2012-08-20  7:45 ` 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).