This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/61402] [C++1y] Init-capture with side effect not working for some types
- From: "thibaut.lutz at googlemail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 03 Jun 2014 11:15:29 +0000
- Subject: [Bug c++/61402] [C++1y] Init-capture with side effect not working for some types
- Auto-submitted: auto-generated
- References: <bug-61402-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61402
--- Comment #1 from Thibaut LUTZ <thibaut.lutz at googlemail dot com> ---
I forgot to add that separating declaration and invocation seems to solve the
problem:
--8<----8<----8<----8<----8<----8<--
#include <iostream>
template<typename T>
void foo(T t) {
using namespace std;
cout << endl << "par t = " << t << endl;
auto test = [ i = ++t ](T v) {
cout << "cap i = ++t = " << i << endl
<< "arg v = " << v << endl;
};
test(t);
}
int main(){
foo(3.14f); // works OK
foo(0); // works OK
foo('a'); // works OK
foo(false); // works OK
}
--8<----8<----8<----8<----8<----8<--