[llvm-bugs] [Bug 43078] New: Clang crashes when it cannot evaluate recursive template

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 21 14:02:43 PDT 2019


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

            Bug ID: 43078
           Summary: Clang crashes when it cannot evaluate recursive
                    template
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: z.zoelec2 at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Found this bug while working on libc++ so the example isn't great. It appears
Clang crashes when it cannot evaluate recursive template parameters. Setting
-ftemplate-depth=100 turns it into an error. Here is the (rather large) example
I have:

template<class _T1, class _T2>
struct __all_const_impl;

template<class..._T1Args, class... _T2Args>
struct __all_const_impl<__tuple_types<_T1Args...>, __tuple_types<_T2Args...>>
    : true_type {};

template<template<class...> class _T1, class... _T1Args, class... _T2Args>
auto __all_const_fn(_T1<_T1Args...>, _T2Args...)
    -> __all_const_impl<__tuple_types<_T1Args...>, __tuple_types<_T2Args...>>;

template<class _T1, class... _T2Args>
using __all_const = decltype(__all_const_fn(declval<_T1>(),
declval<_T2Args>()...));

template<class _Tuple,
         class _Idxs = typename
__make_tuple_indices<tuple_size<_Tuple>::value>::type>
struct foo_impl;

template<class... _Bound, size_t... _Idxs>
struct foo_impl<__tuple_types<_Bound...>, __tuple_indices<_Idxs...>>
{
    std::tuple<_Bound...> __bound;

    template<class... _BoundArgs,
             class = enable_if_t<__all_const<std::tuple<_Bound...>,
                                 _BoundArgs...>::value>>
    foo_impl(_BoundArgs&&... __bound) { }
};

template<class... _Args>
using Foo = foo_impl<__tuple_types<decay_t<_Args>...>>;

static_assert(is_move_constructible<decltype(Foo<int>(1))>::value);

Here is a link to wandbox: https://wandbox.org/permlink/dQwvJViWFJakPfPd

-- 
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/20190821/f80b35cb/attachment.html>


More information about the llvm-bugs mailing list