This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/61402] [C++1y] Init-capture with side effect not working for some types


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]