[llvm-bugs] [Bug 44538] New: Unsized temporary array problem inside template function
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jan 14 02:56:01 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=44538
Bug ID: 44538
Summary: Unsized temporary array problem inside template
function
Product: clang
Version: unspecified
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: m.cencora at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
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);
}
--
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/20200114/9c3ecdcc/attachment.html>
More information about the llvm-bugs
mailing list