7

As my understanding C++17 don't forbid lambda expressions from capturing structured bindings. the below is accepted by gcc but rejected by clang, yet cppreference claim that lambdas can't capture structured bindings.

int arr[] {0, 1};
auto& [a, b] = arr;
auto foo = [&] { b = 9; }; // capturing structured bindings
  1. Is either clang or gcc non-conformant?

  2. Is cppreference wrong in tagging the behavior as part of C++17 ?

Jans
  • 11,064
  • 3
  • 37
  • 45
  • 2
    gcc clean compile, live: https://godbolt.org/z/2FI1Dk – Richard Critten Sep 19 '18 at 19:34
  • 2
    See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85889 – cpplearner Sep 19 '18 at 19:37
  • Sorry, is `clang` that don't accept the code, I fixed the wording, @cpplearner I see, in that case `clang` is wrong in rejecting the code and cppreference also in tagging the behavior as part of C++17. – Jans Sep 19 '18 at 19:37
  • To sum-up cpplearner's link, Clang applies a rule that has not been merged in the c++17 standard. – Oliv Sep 19 '18 at 19:45
  • @Oliv No. Clang applies a rule that was a defect applied to C++17, gcc does not yet implement that defect. – Barry Sep 19 '18 at 19:56

0 Answers0