Skip to content

[Clang] Call to lambda expressions in unevaluated context is improperly rejected by Clang #81145

Closed
@zyn0217

Description

@zyn0217

I'm not confident that I'm summarizing the issue accurately, but here is an example of the case that I discovered while at #70601.

template <class T>
struct S {
  template <class U>
  using Type = decltype([]<class V> {
    return V();
  }.template operator()<U>());
};

S<int>::Type<int> V;

Clang currently rejects the above, complaining that there are no viable functions, which I think is suspicious.

<source>:6:14: error: no matching member function for call to 'operator()'
    4 |   using Type = decltype([]<class V> {
      |                         ~~~~~~~~~~~~~
    5 |     return V();
      |     ~~~~~~~~~~~
    6 |   }.template operator()<U>());
      |   ~~~~~~~~~~~^~~~~~~~~~~~~
<source>:9:9: note: in instantiation of template type alias 'Type' requested here
    9 | S<int>::Type<int> V;
      |         ^
<source>:4:25: note: candidate function template not viable: no known conversion from '(lambda at <source>:4:25)' to 'const S<int>::(lambda at <source>:4:25)' for object argument
    4 |   using Type = decltype([]<class V> {
      |                         ^
1 error generated.

The example is also on godbolt, and we can see that this is accepted by both MSVC and GCC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"lambdaC++11 lambda expressionsrejects-valid

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions