llvm-project/clang/test/SemaCXX/cxx2a-lambda-equals-this.cpp
Tom Honermann ecd0be100b [clang] Warn by default that implicit capture of 'this' is deprecated in C++20 and later.
Previously, a warning that C++20 deprecated implicit capture of 'this' for
lambda captures specified with a capture default of '=' was only issued when
'-Wdeprecated' or '-Wdeprecated-this-capture' was specified. This change
enables the warning by default (it is still only issued when compiling for
C++20 or later). This is consistent with gcc which warns by default (MSVC
requires '/Wall').

Reviewed By: erichkeane, shafik

Differential Revision: https://reviews.llvm.org/D142639
2023-02-02 15:10:47 -05:00

16 lines
403 B
C++

// RUN: %clang_cc1 -std=c++2a -verify %s
// expected-no-diagnostics
// This test does two things.
// Deleting the copy constructor ensures that an [=, this] capture doesn't copy the object.
// Accessing a member variable from the lambda ensures that the capture actually works.
class A {
A(const A &) = delete;
int i;
void func() {
auto L = [=, this]() -> int { return i; };
L();
}
};