[all-commits] [llvm/llvm-project] 0370be: [Clang] Perform derived-to-base conversion on expl...
Sirraide via All-commits
all-commits at lists.llvm.org
Wed May 22 11:16:06 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 0370beb230a35f00b7d07c50ab95f8777662a0c6
https://github.com/llvm/llvm-project/commit/0370beb230a35f00b7d07c50ab95f8777662a0c6
Author: Sirraide <aeternalmail at gmail.com>
Date: 2024-05-22 (Wed, 22 May 2024)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/include/clang/AST/ASTContext.h
M clang/include/clang/Basic/DiagnosticSemaKinds.td
M clang/include/clang/Sema/Sema.h
M clang/lib/CodeGen/CGExpr.cpp
M clang/lib/Sema/SemaLambda.cpp
M clang/lib/Sema/SemaOverload.cpp
M clang/test/CXX/drs/cwg28xx.cpp
M clang/test/CodeGenCXX/cxx2b-deducing-this.cpp
M clang/www/cxx_dr_status.html
Log Message:
-----------
[Clang] Perform derived-to-base conversion on explicit object parameter in lambda (#89828)
Consider this code:
```c++
template <typename... Ts>
struct Overloaded : Ts... { using Ts::operator()...; };
template <typename... Ts>
Overloaded(Ts...) -> Overloaded<Ts...>;
void f() {
int x;
Overloaded o {
[&](this auto& self) {
return &x;
}
};
o();
}
```
To access `x` in the lambda, we need to perform derived-to-base
conversion on `self` (since the type of `self` is not the lambda type,
but rather `Overloaded<(lambda type)>`). We were previously missing this
step, causing us to attempt to load the entire lambda (as the base
class, it would end up being the ‘field’ with index `0` here), which
would then assert later on in codegen.
Moreover, this is only valid in the first place if there is a unique and
publicly accessible cast path from the derived class to the lambda’s
type, so this also adds a check in Sema to diagnose problematic
cases.
This fixes #87210 and fixes #89541.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list