[llvm-bugs] [Bug 26724] New: ICE on complex lambda calls

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Feb 24 03:24:57 PST 2016


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

            Bug ID: 26724
           Summary: ICE on complex lambda calls
           Product: clang
           Version: 3.7
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: tower120 at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

http://coliru.stacked-crooked.com/a/b88b42eebfa5aed1

clang -std=c++14 -O2 -Wall -Wextra -pedantic -pthread main.cpp && ./a.out

Code as is:

#include <type_traits>
#include <iostream>
#include <utility>
#include <cassert>
#include <utility>
#include <functional>
#include <iostream>
#include <string>
#include <vector>


#define CAT1(A, B) A ## B
#define CAT(A, B) CAT1(A, B)

#define ALWAYS_INLINE


/// ----------------------------------------------------------------
/// ----------------------------------------------------------------
///
/// CHANGING to c++14's decltype(auto) solves problem
///
template<class FN1, class FN2, class... Args>
ALWAYS_INLINE constexpr decltype(auto) if_else(std::true_type, FN1 &&fn1, FN2
&&, Args&&... args)
{
     return std::forward<FN1>(fn1)(std::forward<Args>(args)...);
}

template<class FN1, class FN2, class... Args>
ALWAYS_INLINE constexpr decltype(auto) if_else(std::false_type, FN1 &&, FN2
&&fn2, Args&&... args)
{
     return std::forward<FN2>(fn2)(std::forward<Args>(args)...);
}




template<bool do_it, class FN1, class FN2, class... Args>
ALWAYS_INLINE constexpr decltype(auto) if_else(FN1 &&fn1, FN2 &&fn2, Args&&...
args)
{
     return if_else(std::integral_constant<bool,do_it>{}, fn1, fn2,
std::forward<Args>(args)...);
}

template<bool do_it, class FN1, class FN2>
ALWAYS_INLINE constexpr decltype(auto) if_else(FN1 &&fn1, FN2 &&fn2)
{
     return if_else(std::integral_constant<bool,do_it>{}, fn1, fn2,
std::false_type() );      // just a fake unused value
}



// true_type / false_type

template<class bool_const, class FN1, class FN2, class... Args>
ALWAYS_INLINE constexpr decltype(auto) if_else(FN1 &&fn1, FN2 &&fn2, Args&&...
args)
{
    return if_else(std::integral_constant<bool,bool_const::value>{}, fn1, fn2,
std::forward<Args>(args)...);
}

template<class bool_const, class FN1, class FN2>
ALWAYS_INLINE constexpr decltype(auto) if_else(FN1 &&fn1, FN2 &&fn2)
{
    return if_else(std::integral_constant<bool,bool_const::value>{}, fn1, fn2,
std::false_type() );      // just a fake unused value
}

/// ----------------------------------------------------------------
/// ----------------------------------------------------------------

template <typename T>
struct FunctionArity : FunctionArity<decltype(&T::operator())> {};
template <typename R, typename... Args>
struct FunctionArity<R(*)(Args...)> : std::integral_constant<unsigned,
sizeof...(Args)> {};
template <typename R, typename C, typename... Args>
struct FunctionArity<R(C::*)(Args...)> : std::integral_constant<unsigned,
sizeof...(Args)> {};
template <typename R, typename C, typename... Args>
struct FunctionArity<R(C::*)(Args...) const> : std::integral_constant<unsigned,
sizeof...(Args)> {};


template<typename TFunc>
constexpr auto function_arity(TFunc)
{
    return FunctionArity<TFunc>{};
}

#define function_arity_t(...) decltype(function_arity(__VA_ARGS__))


#define Command(name) \
private: Empty CAT(name, _initializer) = [&](){  \
    using fn_arity = function_arity_t( &SelfT:: name );\
    using is_void = std::integral_constant<bool, fn_arity::value==0 >;\
    if_else<is_void::value>( \
        [&](auto&&) { commands.push_back( [&](int ){ name(); }); },      \
        [&](auto&&) { commands.push_back( [&](int i) { name(); }); }     \
    ); \
return Empty(); }(); \
public: void name

struct Test {
    using SelfT = Test;
    struct Empty {};
    using CommandFn = std::function<void(int)>;
    std::vector<CommandFn> commands;

    Command(non_void)(/*int i*/) {

    }
    Command(is_void)() {

    }

};

int main() {
    using namespace std;
}

-- 
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/20160224/58f78830/attachment.html>


More information about the llvm-bugs mailing list