llvm-project/clang/test/SemaCXX/cxx2a-lambda-default-ctor-assign.cpp
David Blaikie 793231c319 [cxx2a] P0624R2 fix: only lambdas with no lambda-capture are default-constructible and assignable.
This is a fix for rG864949 which only disabled default construction and
assignment for lambdas with capture-defaults, where the C++2a draft
disables them for lambdas with any lambda-capture at all.

Patch by Logan Smith!

Differential Revision: https://reviews.llvm.org/D64058

llvm-svn: 365406
2019-07-08 23:24:41 +00:00

23 lines
818 B
C++

// RUN: %clang_cc1 -std=c++2a -verify %s
void no_capture() {
auto x = [] {};
decltype(x) y;
x = x;
x = static_cast<decltype(x)&&>(x);
}
void capture_default(int i) {
auto x = [=] {}; // expected-note 2{{candidate constructor}} expected-note 2{{lambda expression begins here}}
decltype(x) y; // expected-error {{no matching constructor}}
x = x; // expected-error {{cannot be assigned}}
x = static_cast<decltype(x)&&>(x); // expected-error {{cannot be assigned}}
}
void explicit_capture(int i) {
auto x = [i] {}; // expected-note 2{{candidate constructor}} expected-note 2{{lambda expression begins here}}
decltype(x) y; // expected-error {{no matching constructor}}
x = x; // expected-error {{cannot be assigned}}
x = static_cast<decltype(x)&&>(x); // expected-error {{cannot be assigned}}
}