Bug#807842: clang-3.6: compiling c++ code with boost::hana

Gian Lorenzo Meocci glmeocci at gmail.com
Sun Dec 13 17:55:21 UTC 2015


Package: clang-3.6
Version: 1:3.6.2~svn240577-1~exp1
Severity: important

Dear Maintainer,

*** Reporter, please consider answering these questions, where appropriate ***

I' m trying to use boost hana, in particular this example:

#include <boost/hana.hpp>
#include <boost/any.hpp>
#include <cassert>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <utility>
namespace hana = boost::hana;
//! [cases]
template <typename T>
auto case_ = [](auto f) {
  return hana::make_pair(hana::type_c<T>, f);
};
struct default_t;
auto default_ = case_<default_t>;
//! [cases]
//! [process]
template <typename Any, typename Default>
auto process(Any&, std::type_index const&, Default& default_) {
  return default_();
}
template <typename Any, typename Default, typename Case, typename ...Rest>
auto process(Any& a, std::type_index const& t, Default& default_,
             Case& case_, Rest& ...rest)
{
  using T = typename decltype(+hana::first(case_))::type;
  return t == typeid(T) ? hana::second(case_)(*boost::unsafe_any_cast<T>(&a))
                        : process(a, t, default_, rest...);
}
//! [process]
//! [switch_]
template <typename Any>
auto switch_(Any& a) {
  return [&a](auto ...cases_) {
    auto cases = hana::make_tuple(cases_...);
    auto default_ = hana::find_if(cases, [](auto const& c) {
      return hana::first(c) == hana::type_c<default_t>;
    });
    static_assert(default_ != hana::nothing,
      "switch is missing a default_ case");
    auto rest = hana::filter(cases, [](auto const& c) {
      return hana::first(c) != hana::type_c<default_t>;
    });
    return hana::unpack(rest, [&](auto& ...rest) {
      return process(a, a.type(), hana::second(*default_), rest...);
    });
  };
}
//! [switch_]



In order to test it I develop this simple class:

struct X{

    template <typename T>
    void add(T a)
    {
        v.push_back(a);
    }

    template <typename F>
    void map(F f)
    {
        for (auto& e : v)
        {
            switch_(e)(
                case_<int>([f](int c) -> void { f(c); }),
                case_<double>([f](double c) -> void { f(c); }),
                case_<std::string>([f](std::string c) -> void { f(c); }),
                default_([]() -> void { throw std::logic_error("invalid type"); })
            );
        }
    }

    std::vector<boost::any> v;
};


and when I try to compile this code:

    X x;
    x.add("hello!"s);
    x.add(10);
    x.add(1.0f);
    x.add(1.0);

    x.map([](auto e){
        std::cout << e << std::endl;
    });


I get the crash!



*** End of the template - remove these template lines ***


-- System Information:
Debian Release: 8.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.16.0-4-amd64 (SMP w/8 CPU cores)
Locale: LANG=it_IT.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages clang-3.6 depends on:
ii  binutils                 2.25-5
ii  libc6                    2.19-18+deb8u1
ii  libc6-dev                2.19-18+deb8u1
ii  libclang-common-3.6-dev  1:3.6.2~svn240577-1~exp1
ii  libclang1-3.6            1:3.6.2~svn240577-1~exp1
ii  libedit2                 3.1-20140620-2
ii  libffi6                  3.1-2+b2
ii  libgcc-4.9-dev           4.9.2-10
ii  libgcc1                  1:4.9.2-10
ii  libllvm3.6               1:3.6.2~svn240577-1~exp1
ii  libobjc-4.9-dev          4.9.2-10
ii  libstdc++-4.9-dev        4.9.2-10
ii  libstdc++6               4.9.2-10
ii  libtinfo5                5.9+20140913-1+b1
ii  zlib1g                   1:1.2.8.dfsg-2+b1

Versions of packages clang-3.6 recommends:
ii  llvm-3.6-dev  1:3.6.2~svn240577-1~exp1
ii  python        2.7.9-1

Versions of packages clang-3.6 suggests:
pn  clang-3.6-doc  <none>
pn  gnustep        <none>
pn  gnustep-devel  <none>

-- no debconf information



More information about the Pkg-llvm-team mailing list