<html>
<head>
<base href="http://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 --- - Crash with static std::array in template class"
href="http://llvm.org/bugs/show_bug.cgi?id=20037">20037</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Crash with static std::array in template class
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>kyle@mayeses.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=12656" name="attach_12656" title="Preprocessed source">attachment 12656</a> <a href="attachment.cgi?id=12656&action=edit" title="Preprocessed source">[details]</a></span>
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</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>