[llvm-bugs] [Bug 28386] New: Zero-sized array not Sfinae-failure in non-type template parameter
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jul 1 09:02:30 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=28386
Bug ID: 28386
Summary: Zero-sized array not Sfinae-failure in non-type
template parameter
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: lf-bt at thax.hardliners.org
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Classification: Unclassified
#include <type_traits>
template <unsigned int... Is>
struct index_sequence {};
template <bool B> using Sfinae=char (*)[B]; // does not work with msvc+clang;
works with g++
//template <bool B> using Sfinae=char (*)[2*B-1]; // works with g++ and
clang;(msvc does strange things)
//template <bool B> using Sfinae=typename std::enable_if<B,int>::type; //
works.
template <unsigned int N,unsigned int... Is,typename =Sfinae<N==0>>
constexpr index_sequence<Is...> make_index_sequence(...)
{ return {}; }
template <unsigned int N,unsigned int... Is,typename =Sfinae<(N>0)>>
constexpr auto make_index_sequence(...)
-> decltype(make_index_sequence<N-1,N-1,Is...>(index_sequence<>())) //
argument forces ADL
{ return {}; }
int main()
{
index_sequence<0,1> t=make_index_sequence<2>();
}
----
clang++ will happily go from I=0 to I=4294967295 ... until it hits the template
instantiation limit.
According to my and g++'s understanding, using the first version should work,
as zero-size array should lead to an SFINAE failure, just like negative sized
arrays do.
Using the Sfinae-type as function argument instead of as template parameter,
all three versions compile fine, i.e. the zero sized array is treated as SFINAE
failure, e.g.:
template <unsigned int N,unsigned int... Is>
constexpr index_sequence<Is...> make_index_sequence(index_sequence<>
x={},Sfinae<N==0> =0)
...
template <unsigned int N,unsigned int... Is>
constexpr auto make_index_sequence(index_sequence<> x={},Sfinae<(N>0)> =0)
...
(MSVC's problem with the second version has been reported here:
https://connect.microsoft.com/VisualStudio/feedback/details/2881697 )
--
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/20160701/299fad11/attachment.html>
More information about the llvm-bugs
mailing list