<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/96753>96753</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang allows invalid type conversion of lambda from 'void' to 'int' in default argument and template class
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Rush10233
      </td>
    </tr>
</table>

<pre>
    The following code contains an invalid type conversion:

```c++
template <int> 
struct S
{
  friend void foo (int a = []{
    [&](){
 return 0; 
    }();
  }()) {}
};
S<0> t;
```
In line 4 , the default argument value of the integer variable `a` is set to a nested lambda expression with the inner one returning an integer and the outer one returning nothing. The code compiles well in clang, while GCC outputs the following error message:

```c++
<source>: In instantiation of 'struct S<0>':
<source>:10:6:   required from here
   10 | S<0> t;
 |      ^
<source>:8:2: error: could not convert '<lambda closure object>S<0>::<lambda()>().S<0>::<lambda()>()' from 'void' to 'int'
    4 | friend void foo (int a = []{
      |                            ~~~
 5 | [&](){
      | ~~~~~~~~~~~~~~
    6 |  return 0;
      | ~~~~~~~~~
    7 | }();
      | ~~~~
    8 | }()) {}
      | ~^~
      |  |
      |  void
<source>:4:15: note:   when instantiating default argument for call to 'void foo(int) [with int <anonymous> = 0]'
    4 |   friend void foo (int a = []{
      | ^~~
```

Please note that if we replace the template class `S` with a non-template one, clang rejects the code by giving a similar error message with GCC.

[https://godbolt.org/z/v1Gs3Kcf6](https://godbolt.org/z/v1Gs3Kcf6)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVdFyqzYQ_Rr5Zed6QDJgHnhIsJ2505dO0x8QsIA6QnIlYTd9yLd3JLCJY6eT69FgWB2ttLtnj7i1olOIBUmeSbJb8dH12hR_jLaPI8rYqtLNW_Fnj9BqKfVZqA5q3SDUWjkulAWuQKgTl6IB93YMEyc0VmhF2BOJdi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