[LLVMbugs] [Bug 20037] New: Crash with static std::array in template class

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jun 13 21:10:06 PDT 2014


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

            Bug ID: 20037
           Summary: Crash with static std::array in template class
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kyle at mayeses.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 12656
  --> http://llvm.org/bugs/attachment.cgi?id=12656&action=edit
Preprocessed source

I'm pretty sure the code below is valid C++11, but regardless of whether it is
it causes clang to crash.

Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)

#include <array>

namespace detail
{
    template <typename... Types>
    using Sizes = std::array<size_t, sizeof...(Types)>;

    template <typename... Types>
    inline std::array<size_t, sizeof...(Types)> sizes()
    {
        return {{sizeof(Types)...}};
    }
}

template <typename First, typename... Last>
class Variant
{
    static detail::Sizes<First, Last...> sizes;

public:
    template <typename T>
    Variant(T value)
    {
        // Seems to be the cause of the crash
        for (auto size : sizes)
        {
        }
    }
};

template <typename First, typename... Last>
detail::Sizes<First, Last...> Variant<First, Last...>::sizes =
detail::sizes<First, Last...>();

int main()
{
    // Works
    Variant<int, float> b{0};

    // Crashes the compiler
    Variant<int> a{0};
}

Build script:

 "/usr/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all
-disable-free -disable-llvm-verifier -main-file-name Test.cpp
-mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64
-target-linker-version 2.24 -std=c++1y -fdeprecated-macro -ferror-limit 19
-fmessage-length 80 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions
-fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -x
c++ Test-8e0aa8.cpp

-- 
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/20140614/9c9d576c/attachment.html>


More information about the llvm-bugs mailing list