<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - ICE on complex lambda calls"
   href="https://llvm.org/bugs/show_bug.cgi?id=26724">26724</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ICE on complex lambda calls
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.7
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

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

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

        <tr>
          <th>Reporter</th>
          <td>tower120@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="http://coliru.stacked-crooked.com/a/b88b42eebfa5aed1">http://coliru.stacked-crooked.com/a/b88b42eebfa5aed1</a>

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;
}</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>