Are lambda functions nothrow_move_assignable?

clang-cl (4.0.0-trunk) seems yes, but vc2015 (update3) doesn't think so.

Is this implementation specific or does the standard define how lambda functions should be implemented in terms of nothrow and move assignments?

#include <type_traits>
#include <iostream>

template <typename T>
void test_nothrow_move_assignable(T&&) {
  std::cout << std::boolalpha
    << std::is_nothrow_move_assignable<T>::value
    << "\n";
}

int main() {
  test_nothrow_move_assignable([]{});
  return 0;
}

// $ clang-cl.exe scratch.cpp
// $ scratch.exe
// true

// $ cl /nologo /EHsc scratch.cpp
// scratch.cpp
// $ scratch.exe
// false
+4
source share
1 answer

This is a clang error. From [expr.prim.lambda]:

The closure type associated with the lambda expression does not have a default constructor and assigns a remote copy statement . It has a default copy constructor and a default move constructor (12.8).

, , .

+4

Source: https://habr.com/ru/post/1658719/


All Articles