llvm / llvm/llvm-project

[Clang] Lambda in a `decltype()` in template parameters causing incorrect type mismatches

Open
#159,663 3 comments 0 reactions 0 assignees View on GitHub
clang:frontend confirmed rejects-valid
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following code (minimal repro. example)
```cpp
template
struct X {};

template
using DistinctCollector = X;

DistinctCollector getCellSpreadItems()
{
DistinctCollector set;
return set;
}

int main() { getCellSpreadItems(); }
```

https://godbolt.org/z/obMWeKjKr

fails with

`error: no viable conversion from returned value of type 'DistinctCollector<...>' to function return type 'DistinctCollector<...>'`

The same error is not observed on GCC or MSVC (in conformance mode, iow `/permissive-`) compilers.

If you use

```cpp
auto getCellSpreadItems()
{
DistinctCollector set;
return set;
}
```
https://godbolt.org/z/4fnocEr13

it works.

Per @Sirraide on Discord:
> Looking at the AST, it seems like we’re instantiating that template twice; so it seems what it’s complaining about is that the two instances of `DistinctCollector` are ... not the same type, which er, is not quite right
> There are some things we try to diagnose even if the function is still dependent, but usually you need to instantiate it yes, and this also looks like a problem specifically w/ instantiation

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.