<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Unsized temporary array problem inside template function"
href="https://bugs.llvm.org/show_bug.cgi?id=44538">44538</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Unsized temporary array problem inside template function
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>m.cencora@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Temporary unsized arrays declared inside function template, are treated as
unsized in some contexts, and as sized in others.
I.e. decltype always returns int (&&)[3], but range based for-loop sometimes
treats it as unsized (and incomplete).
Reproducer:
#include <type_traits>
using Array = int[];
template <typename ...Ts>
void bar1(Ts ...values)
{
auto && array1 = Array{ 1, 2, 3 };
auto && array2 = Array{ values...};
static_assert(std::is_same<int (&&)[3], decltype(array1)>{}, ""); //
ok
static_assert(std::is_same<decltype(array1), decltype(array2)>{}, ""); //
ok
for (auto c : array1) {} // ok
for (auto c : array2) {} // does not compile, says array2 has incomplete
type int[]
}
template <typename T1, typename T2, typename T3>
void bar2(T1 v1, T2 v2, T3 v3)
{
auto && array1 = Array{ 1, 2, 3 };
auto && array2 = Array{ v1, v2, v3 };
auto && array3 = Array{ (int)v1, (int) v2, (int)v3 };
static_assert(std::is_same<int (&&)[3], decltype(array1)>{}, ""); //
ok
static_assert(std::is_same<decltype(array1), decltype(array2)>{}, ""); //
ok
static_assert(std::is_same<decltype(array1), decltype(array3)>{}, ""); //
ok
for (auto c : array1) {} // ok
for (auto c : array2) {} // does not compile, says array2 has incomplete
type int[]
for (auto c : array3) {} // ok
}
void bar3(int a, int b, int c)
{
auto && array1 = Array{ 1, 2, 3 };
auto && array2 = Array{ a, b, c };
static_assert(std::is_same<int (&&)[3], decltype(array1)>{}, ""); //
ok
static_assert(std::is_same<decltype(array1), decltype(array2)>{}, ""); //
ok
for (auto c : array1) {} // ok
for (auto c : array2) {} // ok
}
int main()
{
bar1<int, int, int>(1, 2, 3);
bar2<int, int, int>(1, 2, 3);
bar3(1, 2, 3);
}</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>