<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 --- - poor diagnostic for deduction failure in default template argument"
href="http://llvm.org/bugs/show_bug.cgi?id=15673">15673</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>poor diagnostic for deduction failure in default template argument
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>zilla@kayari.org
</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>The change made by
<a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120507/057436.html">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120507/057436.html</a>
is excellent, but only seems to work for old fashioned uses of enable_if, in
return types or function parameters.
My preferred style is to de-clutter the function declaration by using enable_if
in a template parameter with a default template argument e.g.
#include <type_traits>
template<typename T>
struct a_trait : std::false_type { };
template<typename T,
typename Requires = typename std::enable_if<a_trait<T>::value>::type>
void foo() { }
int main()
{
foo<int>();
}
Clang is not very helpful here:
b.cc:12:5: error: no matching function for call to 'foo'
foo<int>();
^~~~~~~~
b.cc:8:6: note: candidate template ignored: couldn't infer template argument
'Requires'
void foo() { }
^
In an ideal world it would even recognise this is an equivalent use of
enable_if
#include <type_traits>
template<typename T>
struct some_trait : std::false_type { };
template<typename T>
struct a_pony
: std::enable_if<some_trait<T>::value>
{ };
template<typename T,
typename Requires = typename a_pony<T>::type>
void foo() { }
int main()
{
foo<int>();
}
And also recognise my preferred form of using enable_if constraints via alias
templates:
#include <type_traits>
template<typename T>
struct some_trait : std::false_type { };
template<typename T>
using unicorns
= typename std::enable_if<some_trait<T>::value>::type;
template<typename T,
typename Requires = unicorns<T>>
void foo() { }
int main()
{
foo<int>();
}
(unicorns might be simpler than a_pony since there's no other type involved,
just an alias for enable_if)</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>