<html>
<head>
<base href="https://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 --- - Produce more information when template substitution fails" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24252&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=xXG_-UDaLJ-DuMlhYJSZwtf03F1qX80uMHP_eSw6WRw&s=IdCrL1QfIuJfV_ba5iOm5qcApk_SiPW7m4sX_6cjyp8&e=">24252</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Produce more information when template substitution fails
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dnovillo@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>For the following code:
template <class T> typename T::inner_type Foo() {}
template <class T> decltype(Foo<T>()) Bar() {}
template <class T> decltype(Bar<T>()) Baz() {}
int main() {
Baz<int>();
}
Clang produces:
$ clang -c -std=c++11 foo.cc
16947782.cpp:6:3: error: no matching function for call to 'Baz'
Baz<int>();
^~~~~~~~
foo.cc:3:39: note: candidate template ignored: substitution failure [with T =
int]: no matching function for call to 'Bar'
template <class T> decltype(Bar<T>()) Baz() {}
~~~ ^
That's not very helpful because it doesn't say why there was no matching
function to call 'Bar'. GCC says this:
error: no matching function for call to 'Baz()'
note: candidate is:
note: template<class T> decltype (Bar<T>()) n::{anonymous}::Baz()
note: template argument deduction/substitution failed:
In substitution of 'template<class T> decltype (Bar<T>())
n::{anonymous}::Baz() [with T = int]':
required from here
error: no matching function for call to 'Bar()'
note: candidate is:
note: template<class T> decltype (Foo<T>()) n::{anonymous}::Bar()
note: template argument deduction/substitution failed:
In substitution of 'template<class T> decltype (Foo<T>())
n::{anonymous}::Bar() [with T = int]':
required by substitution of 'template<class T> decltype (Bar<T>())
n::{anonymous}::Baz() [with T = int]'
required from here
error: no matching function for call to 'Foo()'
note: candidate is:
note: template<class T> typename T::inner_type n::{anonymous}::Foo()
note: template argument deduction/substitution failed:
In substitution of 'template<class T> typename T::inner_type
n::{anonymous}::Foo() [with T = int]':
required by substitution of 'template<class T> decltype (Foo<T>())
n::{anonymous}::Bar() [with T = int]'
required by substitution of 'template<class T> decltype (Bar<T>())
n::{anonymous}::Baz() [with T = int]'
required from here
error: 'int' is not a class, struct, or union type
That's better. We can't call Baz<int>() because we can't call Bar<int>()
because we can't call Foo<int>() because 'int' is not a class. Would be nice if
clang could produce a similar error message.
Note that GCC will print a substitution stack for every overload that gets
disabled by SFINAE, which effectively becomes a substitution tree. This is very
useful. Here's an example:
template <class T> typename T::inner_type Foo() {}
template <class T> decltype(Foo<T>()) Bar() {}
// Baz is overloaded.
template <class T> decltype(Bar<T>()) Baz() {}
template <class T> decltype(Bar<const T>()) Baz() {}
int main() {
Baz<int>();
}
GCC says:
error: no matching function for call to 'Baz()'
note: candidates are:
note: template<class T> decltype (Bar<T>()) n::{anonymous}::Baz()
note: template argument deduction/substitution failed:
In substitution of 'template<class T> decltype (Bar<T>())
n::{anonymous}::Baz() [with T = int]':
required from here
error: no matching function for call to 'Bar()'
note: candidate is:
note: template<class T> decltype (Foo<T>()) n::{anonymous}::Bar()
note: template argument deduction/substitution failed:
In substitution of 'template<class T> decltype (Foo<T>())
n::{anonymous}::Bar() [with T = int]':
required by substitution of 'template<class T> decltype (Bar<T>())
n::{anonymous}::Baz() [with T = int]'
required from here
error: no matching function for call to 'Foo()'
note: candidate is:
note: template<class T> typename T::inner_type n::{anonymous}::Foo()
note: template argument deduction/substitution failed:
In substitution of 'template<class T> typename T::inner_type
n::{anonymous}::Foo() [with T = int]':
required by substitution of 'template<class T> decltype (Foo<T>())
n::{anonymous}::Bar() [with T = int]'
required by substitution of 'template<class T> decltype (Bar<T>())
n::{anonymous}::Baz() [with T = int]'
required from here
error: 'int' is not a class, struct, or union type
note: template<class T> decltype (Bar<const T>()) n::{anonymous}::Baz()
note: template argument deduction/substitution failed:
In substitution of 'template<class T> decltype (Bar<const T>())
n::{anonymous}::Baz() [with T = int]':
required from here
error: no matching function for call to 'Bar()'
note: candidate is:
note: template<class T> decltype (Foo<T>()) n::{anonymous}::Bar()
note: template argument deduction/substitution failed:
In substitution of 'template<class T> decltype (Foo<T>())
n::{anonymous}::Bar() [with T = const int]':
required by substitution of 'template<class T> decltype (Bar<const T>())
n::{anonymous}::Baz() [with T = int]'
required from here
error: no matching function for call to 'Foo()'
note: candidate is:
note: template<class T> typename T::inner_type n::{anonymous}::Foo()
note: template argument deduction/substitution failed:
In substitution of 'template<class T> typename T::inner_type
n::{anonymous}::Foo() [with T = const int]':
required by substitution of 'template<class T> decltype (Foo<T>())
n::{anonymous}::Bar() [with T = const int]'
required by substitution of 'template<class T> decltype (Bar<const T>())
n::{anonymous}::Baz() [with T = int]'
required from here
error: 'const int' is not a class, struct, or union type
Note how GCC explains why neither of the two overloads of Baz() can be called.</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>