[llvm-bugs] [Bug 43090] New: self reference function variable cannot deduce auto return type

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 22 07:49:32 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43090

            Bug ID: 43090
           Summary: self reference function variable cannot deduce auto
                    return type
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: adrianh.bsc at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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 https://godbolt.org/z/58VELd for demo.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190822/cd51041f/attachment.html>


More information about the llvm-bugs mailing list