ladybird/Tests/ClangPlugins/LambdaTests/lambda_capture_local_by_ref.cpp
Matthew Olsson 6a4938a524 ClangPlugins: Convert all warnings to errors
Now that the lambda capture plugin isn't full of false-positives, we can
make the jump and start halting builds for these errors. It also allows
these plugins to be useful in CI.
2024-05-22 21:55:34 -06:00

27 lines
645 B
C++

/*
* Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
// RUN: %clang++ -cc1 -verify %plugin_opts% %s 2>&1
#include <AK/Function.h>
void take_fn(Function<void()>) { }
void take_fn_escaping(ESCAPING Function<void()>) { }
void test()
{
// expected-note@+1 {{Annotate the variable declaration with IGNORE_USE_IN_ESCAPING_LAMBDA if it outlives the lambda}}
int a = 0;
take_fn([&a] {
(void)a;
});
// expected-error@+1 {{Variable with local storage is captured by reference in a lambda marked ESCAPING}}
take_fn_escaping([&a] {
(void)a;
});
}