<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - self reference function variable cannot deduce auto return type"
   href="https://bugs.llvm.org/show_bug.cgi?id=43090">43090</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>self reference function variable cannot deduce auto return type
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>release blocker
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++17
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>adrianh.bsc@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This appears to be a bug.  The following sample doesn't compile under LLVM but
does under gcc and msvc:

-----8<--------------------8<---------------
#define USE_TEMPLATE 0
#if USE_TEMPLATE

template <typename I>
constexpr auto fn(I i)

#else

auto fn = [](auto i) constexpr

#endif
{
    if constexpr (i() == 0)
        return fn([i]{return i() + 1;});
    else
        return 1;
};

int main()
{
    return fn([]{ return 0;});
}
---------------->8-------------------->8----

It give the following error:

<source>:14:16: error: variable 'fn' declared with deduced type 'auto' cannot
appear in its own initializer
        return fn([i]{return i() + 1;});
               ^

See <a href="https://godbolt.org/z/58VELd">https://godbolt.org/z/58VELd</a> for demo.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>