[LLVMbugs] [Bug 13136] New: Clang fails to compile non-type template parameter pack deduction in template alias
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Jun 18 03:02:34 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=13136
Bug #: 13136
Summary: Clang fails to compile non-type template parameter
pack deduction in template alias
Product: clang
Version: trunk
Platform: Macintosh
OS/Version: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: C++11
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: jonathan.sauer at gmx.de
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
The following code does not compile with clang r158654:
template <typename T, T... Numbers>
struct NumberTuple { };
template <unsigned int... Numbers>
using MyNumberTuple = NumberTuple<unsigned int, Numbers...>;
template <typename U, unsigned int... Numbers>
void foo(U&&, MyNumberTuple<Numbers...>) // Does not compile
//void foo(U&&, NumberTuple<unsigned int, Numbers...>) // Compiles
{
}
// Compiles iff <foo> compiles
template <typename U, unsigned int... Numbers>
void bar(U&&, NumberTuple<unsigned int, Numbers...>)
{
}
template <unsigned int... Numbers>
void baz(MyNumberTuple<Numbers...>) // Compiles even with alias
{
}
int main()
{
foo(1, NumberTuple<unsigned int, 0, 1>());
bar(1, NumberTuple<unsigned int, 0, 1>());
baz(NumberTuple<unsigned int, 0, 1>());
}
This results in:
$ ~/LLVM/build/Release+Asserts/bin/clang++ -std=c++11 clang.cpp
clang.cpp:26:5: error: no matching function for call to 'foo'
foo(1, NumberTuple<unsigned int, 0, 1>());
^~~
clang.cpp:8:6: note: candidate function [with U = int, Numbers = <>] not
viable: no known conversion
from 'NumberTuple<unsigned int, 0, 1>' to 'MyNumberTuple<>'
(aka 'NumberTuple<unsigned int, >') for 2nd argument;
void foo(U&&, MyNumberTuple<Numbers...>) // Does not compile
^
clang.cpp:27:5: error: no matching function for call to 'bar'
bar(1, NumberTuple<unsigned int, 0, 1>());
^~~
clang.cpp:15:6: note: candidate function [with U = int, Numbers = <>] not
viable: no known
conversion from 'NumberTuple<unsigned int, 0, 1>' to
'NumberTuple<unsigned int>' for 2nd
argument;
void bar(U&&, NumberTuple<unsigned int, Numbers...>)
^
2 errors generated.
It seems that there are two parts to this issue:
1. Clang fails to correctly deduce the non-type template parameters in the call
to <foo> when <foo> uses a template alias instead of the template itself as the
type of the corresponding function argument. This only happens if the function
has an additional template parameter (as <baz> compiles correctly despite using
a template alias).
2. Recovery from that error does not work correctly, resulting in clang failing
template parameter deduction in the call to <bar>. This can be demonstrated by
commenting line 'Does not compile' and uncommenting line 'Compiles'; after this
change, both function calls compile correctly.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list