Skip to content

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

@Metadorius

Description

@Metadorius

The following code (minimal repro. example)

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyrejects-valid

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions