[LLVMbugs] [Bug 22479] New: compiler crash when doing lambda magic

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Feb 5 11:36:00 PST 2015


http://llvm.org/bugs/show_bug.cgi?id=22479

            Bug ID: 22479
           Summary: compiler crash when doing lambda magic
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: janezz55 at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 13813
  --> http://llvm.org/bugs/attachment.cgi?id=13813&action=edit
the required attackment

Try compiling this and you'll get a crash:

#ifndef GENERIC_CIFY_HPP
# define GENERIC_CIFY_HPP
# pragma once

#include <utility>

namespace generic
{

namespace
{

template <typename F, int I, typename L, typename R, typename ...A>
inline F cify(L&& l, R (*)(A...))
{
  static thread_local L l_(::std::forward<L>(l));
  static thread_local bool full;

  if (full)
  {
    l_.~L();
    new (static_cast<void*>(&l_)) L(::std::forward<L>(l));
  }
  else
  {
    full = true;
  }

  return [](A... args) noexcept(noexcept(l_(::std::forward<A>(args)...))) {
    return l_(::std::forward<A>(args)...);
  };
}

}

template <typename F, int I = 0, typename L>
inline F cify(L&& l)
{
  return cify<F, I>(::std::forward<L>(l), F());
}

}

#endif // GENERIC_CIFY_HPP

#include <iostream>

int main()
{
  int a;

  auto const f(::generic::cify<void(*)()>([a]{::std::cout << "a: " << a <<
::std::endl;}));

  f();

  return 0;
}

-- 
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/20150205/8c25c944/attachment.html>


More information about the llvm-bugs mailing list