It seems that nvcc
error messages are significantly less informative regarding concepts than the underlying gcc
. As an example, take this code:
#include <type_traits>
struct S
{
template <typename T> requires std::is_same_v<T, int>
void foo(T)
{
}
template <typename T> requires std::is_same_v<T, double>
void foo(T)
{
}
};
int main()
{
S s;
s.foo(1);
s.foo(1.);
s.foo(1u);
}
In nvcc
, this produces (Godbolt link):
<source>(23): error: no instance of overloaded function "S::foo" matches the argument list
argument types are: (unsigned int)
object type is: S
1 error detected in the compilation of "<source>".
ASM generation compiler returned: 2
<source>(23): error: no instance of overloaded function "S::foo" matches the argument list
argument types are: (unsigned int)
object type is: S
1 error detected in the compilation of "<source>".
Execution build compiler returned: 2
Contrast this to gcc
(Godbolt link):
<source>: In function 'int main()':
<source>:23:10: error: no matching function for call to 'S::foo(unsigned int)'
23 | s.foo(1u);
| ~~~~~^~~~
<source>:6:10: note: candidate: 'template<class T> requires is_same_v<T, int> void S::foo(T)'
6 | void foo(T)
| ^~~
<source>:6:10: note: template argument deduction/substitution failed:
<source>:6:10: note: constraints not satisfied
<source>: In substitution of 'template<class T> requires is_same_v<T, int> void S::foo(T) [with T = unsigned int]':
<source>:23:10: required from here
<source>:6:10: required by the constraints of 'template<class T> requires is_same_v<T, int> void S::foo(T)'
<source>:5:41: note: the expression 'is_same_v<T, int> [with T = unsigned int]' evaluated to 'false'
5 | template <typename T> requires std::is_same_v<T, int>
| ~~~~~^~~~~~~~~~~~~~~~~
<source>:11:10: note: candidate: 'template<class T> requires is_same_v<T, double> void S::foo(T)'
11 | void foo(T)
| ^~~
<source>:11:10: note: template argument deduction/substitution failed:
<source>:11:10: note: constraints not satisfied
<source>: In substitution of 'template<class T> requires is_same_v<T, double> void S::foo(T) [with T = unsigned int]':
<source>:23:10: required from here
<source>:11:10: required by the constraints of 'template<class T> requires is_same_v<T, double> void S::foo(T)'
<source>:10:41: note: the expression 'is_same_v<T, double> [with T = unsigned int]' evaluated to 'false'
10 | template <typename T> requires std::is_same_v<T, double>
| ~~~~~^~~~~~~~~~~~~~~~~~~~
ASM generation compiler returned: 1
<source>: In function 'int main()':
<source>:23:10: error: no matching function for call to 'S::foo(unsigned int)'
23 | s.foo(1u);
| ~~~~~^~~~
<source>:6:10: note: candidate: 'template<class T> requires is_same_v<T, int> void S::foo(T)'
6 | void foo(T)
| ^~~
<source>:6:10: note: template argument deduction/substitution failed:
<source>:6:10: note: constraints not satisfied
<source>: In substitution of 'template<class T> requires is_same_v<T, int> void S::foo(T) [with T = unsigned int]':
<source>:23:10: required from here
<source>:6:10: required by the constraints of 'template<class T> requires is_same_v<T, int> void S::foo(T)'
<source>:5:41: note: the expression 'is_same_v<T, int> [with T = unsigned int]' evaluated to 'false'
5 | template <typename T> requires std::is_same_v<T, int>
| ~~~~~^~~~~~~~~~~~~~~~~
<source>:11:10: note: candidate: 'template<class T> requires is_same_v<T, double> void S::foo(T)'
11 | void foo(T)
| ^~~
<source>:11:10: note: template argument deduction/substitution failed:
<source>:11:10: note: constraints not satisfied
<source>: In substitution of 'template<class T> requires is_same_v<T, double> void S::foo(T) [with T = unsigned int]':
<source>:23:10: required from here
<source>:11:10: required by the constraints of 'template<class T> requires is_same_v<T, double> void S::foo(T)'
<source>:10:41: note: the expression 'is_same_v<T, double> [with T = unsigned int]' evaluated to 'false'
10 | template <typename T> requires std::is_same_v<T, double>
| ~~~~~^~~~~~~~~~~~~~~~~~~~
Execution build compiler returned: 1
Is there anything that can be done on the user-side? If not, is it possible to improve this for future versions? One of the big appeals for concepts is that the error messages for templated code are so much more detailed and informative.