[LLVMbugs] [Bug 24252] New: Produce more information when template substitution fails
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Jul 24 13:03:23 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=24252
Bug ID: 24252
Summary: Produce more information when template substitution
fails
Product: clang
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: dnovillo at google.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
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.
--
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/20150724/9e6f2be6/attachment.html>
More information about the llvm-bugs
mailing list