Issue 159663
Summary [Clang] Lambda in a `decltype()` in template parameters causing incorrect type mismatches
Labels clang
Assignees
Reporter Metadorius
    The following code (minimal repro. example)
```cpp
template <typename T>
struct X {};

template <typename>
using DistinctCollector = X<decltype([]{})>;

DistinctCollector<int*> getCellSpreadItems()
{
	DistinctCollector<int*> 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<int*> 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<T>` 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
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to