<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/65067>65067</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Regression introduced with implementation of P2036R3 (assertion error)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
alejandro-alvarez-sonarsource
</td>
</tr>
</table>
<pre>
Hello,
Commit 93d7002dc4644b0a6f15a998dff0d55c72012e87 introduced a regression. A reproducing snippet:
```cpp
template <typename T> T &declval() noexcept {}
template <typename T> struct FakeVoidToVoid {};
template <typename Func> inline auto call(Func &&func) { return func(); }
template <typename Func>
using NormalizedCallResult = FakeVoidToVoid<decltype(call(declval<Func>()))>;
template <typename T> class SemiFuture {
public:
template <typename Func> auto then(Func &&func) {
return and_then(wrapCB<T>(func));
}
template <typename Func> auto and_then(Func &&func) {
using Result = NormalizedCallResult<Func>;
}
protected:
template <typename RawArg, typename Func> auto wrapCB(Func &&func) {
return [func = func](auto... args) -> SemiFuture<decltype(func(args...))> {return {};};
}
};
auto removeDocumentsInRange(SemiFuture<void> waitForActiveQueriesToComplete) {
return waitForActiveQueriesToComplete.then([]() {});
}
```
This has been reduced from code coming from [MongoDB](https://github.com/mongodb/mongo/blob/e2674b6d474f5eabde5eb44e6a8396ccb6d6fc53/src/mongo/util/future.h#L1367).
Before 93d7002dc4644b0a6f15a998dff0d55c72012e87, the `func` in `decltype(func(args...)` would refer to the parameter `func`. After the commit, it would refer to the variable `func` introduced by the capture. It looks like other parts of the parser (i,e, `TemplateInstantiator::TransformDecl`) do not expect to find a `VarDecl` and fail to handle them.
This regression happens for C++14 and higher, even though "Change scope of lambda trailing-return-type" was introduced with C++23.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVl1v2zoS_TX0yyCCTEqy9OAHf9TYAruL3VyjrxcjamSxpUiBpJy2v_6Ckpy4aZs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