# Template bug

**URL:** <https://forums.developer.nvidia.com/t/template-bug/17326>\
**Category:** CUDA Programming and Performance\
**Created:** [June 25, 2010, 4:48am UTC](https://forums.developer.nvidia.com/t/template-bug/17326 "2010-06-25T04:48:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bb\_vb](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@bb\_vb](https://forums.developer.nvidia.com/u/bb_vb)\
**Post date:** [June 25, 2010, 4:48am UTC](https://forums.developer.nvidia.com/t/template-bug/17326/1 "2010-06-25T04:48:07Z")

</div>

The following code compiles fine using g++ (4.1.2 20080704 (Red Hat 4.1.2-44)), but does not compile using nvcc (2.3 or 3.0):

[codebox]template\<int DIM, class T\>

void get(const T& x) {

```
x.get<DIM>();

```

}

struct A {

```
template<int DIM>

void get() const {}

```

};

int main()

{

```
A a;

get<3>(a);

```

}[/codebox]

The error given by nvcc is:

[codebox]In function â€˜void get(const T&) [with int DIM = 3, T = A]â€™:

```
instantiated from here

```

error: no matching function for call to â€˜A::get() constâ€™[/codebox]

Referring to the 3rd line of code.

Any ideas why this might be? Compiler bug?

Cheers,

Ben

---

<div class="post-metadata">

**Author:** ![JaredHoberock](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jaredhoberock/32/166135_2.png) [@JaredHoberock](https://forums.developer.nvidia.com/u/JaredHoberock)\
**Post date:** [June 25, 2010, 7:16pm UTC](https://forums.developer.nvidia.com/t/template-bug/17326/2 "2010-06-25T19:16:21Z")

</div>

I think you mean the following, right?

[codebox]

struct A {

```
template<int DIM>

void get() const {}

```

};

int main()

{

```
A a;

a.get<3>();

```

}

[/codebox]

This code seems to compile with a recent nightly compiler:

[codebox]

jhoberock@jhoberock-dt:~$ cat get.cu ; nvcc get.cu ; echo ; nvcc --version

struct A {

```
template<int DIM>

void get() const {}

```

};

int main()

{

```
A a;

a.get<3>();

```

}

nvcc: NVIDIA ® Cuda compiler driver

Copyright © 2005-2010 NVIDIA Corporation

Built on Fri\_May\_28\_21:28:40\_CDT\_2010

Cuda compilation tools, release 3.1, V0.2.1221

[/codebox]

Have you tried nvcc 3.1b?

---

<div class="post-metadata">

**Author:** ![JaredHoberock](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jaredhoberock/32/166135_2.png) [@JaredHoberock](https://forums.developer.nvidia.com/u/JaredHoberock)\
**Post date:** [June 25, 2010, 7:25pm UTC](https://forums.developer.nvidia.com/t/template-bug/17326/3 "2010-06-25T19:25:59Z")

</div>

Whoops, you’re right – I copied your code wrong. I can reproduce this. I’ll file a bug.

---

<div class="post-metadata">

**Author:** ![chippies](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/chippies/32/47952_2.png) [@chippies](https://forums.developer.nvidia.com/u/chippies)\
**Post date:** [June 25, 2010, 11:16pm UTC](https://forums.developer.nvidia.com/t/template-bug/17326/4 "2010-06-25T23:16:11Z")

</div>

Just noticed something about the definition of void get(const T&):

```auto
template<int DIM, class T>

void get(const T& x) {

	x.get<DIM>();

}

```

But the calling line in main is

```auto
get<3>(a);

```

Shouldn’t there be two parameters in the template?

```auto
get<3, A>(a);

```

---

<div class="post-metadata">

**Author:** ![JaredHoberock](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jaredhoberock/32/166135_2.png) [@JaredHoberock](https://forums.developer.nvidia.com/u/JaredHoberock)\
**Post date:** [June 26, 2010, 2:37am UTC](https://forums.developer.nvidia.com/t/template-bug/17326/5 "2010-06-26T02:37:48Z")

</div>

> [@](#):
>
> Just noticed something about the definition of void get(const T&):
> 
> ```auto
> template<int DIM, class T>
> 
> void get(const T& x) {
> 
> x.get<DIM>();
> 
> }
> 
> ```
> 
> But the calling line in main is
> 
> ```auto
> get<3>(a);
> 
> ```
> 
> Shouldn’t there be two parameters in the template?
> 
> ```auto
> get<3, A>(a);
> 
> ```

The compiler can figure out the what the 2nd parameter should be from the context.

---

<div class="post-metadata">

**Author:** ![bb\_vb](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@bb\_vb](https://forums.developer.nvidia.com/u/bb_vb)\
**Post date:** [June 27, 2010, 10:42pm UTC](https://forums.developer.nvidia.com/t/template-bug/17326/6 "2010-06-27T22:42:56Z")

</div>

> [@](#):
>
> Whoops, you’re right – I copied your code wrong. I can reproduce this. I’ll file a bug.

Thanks Jared.
