[llvm-bugs] [Bug 44650] New: "Recursive template instantiation exceeded maximum depth" for innocent-looking code.

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 24 04:19:20 PST 2020


            Bug ID: 44650
           Summary: "Recursive template instantiation exceeded maximum
                    depth" for innocent-looking code.
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: officesamurai at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Created attachment 23050
  --> https://bugs.llvm.org/attachment.cgi?id=23050&action=edit
The original test case

I've got this problem on Alpine Linux originally.
# cat /etc/os-release
NAME="Alpine Linux"
PRETTY_NAME="Alpine Linux v3.11"

# clang -v
Alpine clang version 9.0.0 (https://git.alpinelinux.org/aports
f7f0d2c2b8bcd6a5843401a9a702029556492689) (based on LLVM 9.0.0)
Target: x86_64-alpine-linux-musl
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation:
Found candidate GCC installation: /usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-alpine-linux-musl/9.2.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

# clang++ -c test_alpine1.cpp
In file included from test_alpine1.cpp:1:
In file included from
fatal error: recursive template instantiation exceeded maximum depth of 1024
      template<typename _Up, typename _Up2 = __remove_cvref_t<_Up>>

#include <functional>

using function = std::function<void()>;

struct S

    void operator()() const

auto test()
    function f;
    return S(std::ref(f));

The interesting thing here is that if I remove S::operator(), the compilation

P.S. I've tried to minimize it further by replacing std::function with a
trivial struct and in the resulting code the operator() is no longer needed to
reproduce the error (see test_alpine2.cpp).

P.S.2 I've also tried to get rid of things specific to the stdlib used on
Alpine and got test_anywhere.cpp, which fails to compile with the same error on
other systems as well. Namely, I've tried it on LinuxMint 17.3 where I have
more versions of Clang installed and it fails virtually for all of them (4.x -

P.S.3 GCC is able to compile all of the files.

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/20200124/c96712c0/attachment.html>

More information about the llvm-bugs mailing list