Files
TheRock/compiler/amd-llvm/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

152 lines
4.0 KiB
Plaintext

// RUN: %clang_cc1 -triple i686-pc-linux -std=c++11 -fblocks %s -verify
void block_capture_errors() {
__block int var; // expected-note 2{{'var' declared here}}
(void)[var] { }; // expected-error{{__block variable 'var' cannot be captured in a lambda}}
(void)[=] { var = 17; }; // expected-error{{__block variable 'var' cannot be captured in a lambda}}
}
void conversion_to_block(int captured) {
int (^b1)(int) = [=](int x) { return x + captured; };
const auto lambda = [=](int x) { return x + captured; };
int (^b2)(int) = lambda;
}
template<typename T>
class ConstCopyConstructorBoom {
public:
ConstCopyConstructorBoom(ConstCopyConstructorBoom&);
ConstCopyConstructorBoom(const ConstCopyConstructorBoom&) {
T *ptr = 1; // expected-error{{cannot initialize a variable of type 'float *' with an rvalue of type 'int'}}
}
void foo() const;
};
void conversion_to_block_init(ConstCopyConstructorBoom<int> boom,
ConstCopyConstructorBoom<float> boom2) {
const auto& lambda1([=] { boom.foo(); }); // okay
const auto& lambda2([=] { boom2.foo(); }); // expected-note{{in instantiation of member function}}
void (^block)(void) = lambda2;
}
void nesting() {
int array[7]; // expected-note 2{{'array' declared here}}
[=] () mutable {
[&] {
^ {
int i = array[2];
i += array[3];
}();
}();
}();
[&] {
[=] () mutable {
^ {
int i = array[2]; // expected-error{{cannot refer to declaration with an array type inside block}}
i += array[3];
}();
}();
[=] () mutable {
^ {
int i = 0;
i += array[3]; // expected-error{{cannot refer to declaration with an array type inside block}}
}();
}();
}();
}
namespace overloading {
void bool_conversion() {
if ([](){}) { // expected-warning{{address of lambda function pointer conversion operator will always evaluate to 'true'}}
}
bool b = []{}; // expected-warning{{address of lambda function pointer conversion operator will always evaluate to 'true'}}
b = (bool)[]{};
}
void conversions() {
int (*fp)(int) = [](int x) { return x + 1; };
fp = [](int x) { return x + 1; };
typedef int (*func_ptr)(int);
fp = (func_ptr)[](int x) { return x + 1; };
int (^bp)(int) = [](int x) { return x + 1; };
bp = [](int x) { return x + 1; };
typedef int (^block_ptr)(int);
bp = (block_ptr)[](int x) { return x + 1; };
}
int &accept_lambda_conv(int (*fp)(int));
float &accept_lambda_conv(int (^bp)(int));
void call_with_lambda() {
int &ir = accept_lambda_conv([](int x) { return x + 1; });
}
template<typename T> using id = T;
auto a = [](){};
struct C : decltype(a) {
using decltype(a)::operator id<void(*)()>;
private:
using decltype(a)::operator id<void(^)()>;
} extern c;
struct D : decltype(a) {
using decltype(a)::operator id<void(^)()>;
private:
using decltype(a)::operator id<void(*)()>; // expected-note {{here}}
} extern d;
bool r1 = c; // expected-warning{{address of lambda function pointer conversion operator will always evaluate to 'true'}}
bool r2 = d; // expected-error {{private}} \
expected-warning{{address of lambda function pointer conversion operator will always evaluate to 'true'}}
}
namespace PR13117 {
struct A {
template<typename ... Args> static void f(Args...);
template<typename ... Args> static void f1()
{
(void)^(Args args) { // expected-error{{expression contains unexpanded parameter pack 'Args'}}
};
}
template<typename ... Args> static void f2()
{
f(
^(Args args)
{ }
...
);
}
template<typename ... Args> static void f3()
{
(void)[](Args args) { // expected-error{{expression contains unexpanded parameter pack 'Args'}}
};
}
template<typename ... Args> static void f4()
{
f([](Args args) { } ...);
}
};
void g() {
A::f1<int, int>();
A::f2<int, int>();
}
}