[cfe-dev] clang fails to match definition of class template member function

Douglas Gregor dgregor at apple.com
Mon Sep 24 11:00:55 PDT 2012


On Sep 23, 2012, at 11:29 PM, KARTHIKVENKATESH BHAT <kv.bhat at samsung.com> wrote:

> Hi All,
> We were looking into templates implementation in clang and came across an issue in template implementation of clang.
> When we try to compile the following code-
> 
> template <int dim> class X {};
> template <class T> struct Y {
>  static const unsigned int dim = 1;
>  template <class U> X<Y<T>::dim> f();
> };
> template <class T> template <class U> 
> X<Y<T>::dim> Y<T>::f() { return X<dim>(); }
> int main()
> {
>  Y<int>().f<int>();
> }
> 
> the compilation fails with error -
> error: out-of-line definition of 'f' does not match any declaration in 'Y<T>' 
> X<Y<T>::dim> Y<T>::f() { return X<dim>(); }
> 
> This compiles successfully in case of gcc and intel compiler.
> 
> Upon debugging we found that the return type for the definition and declaration are mismatatching resulting in this error.
> 
> We also found that in case of templates  in Sema::CheckTemplateIdType function we use cannonType actually represents 
> TemplateSpecializationType which might be causing the issue.
> 
> Would like few inputs from community about fixing this issue. 


You should focus your attention on Sema::RebuildTypeInCurrentInstantiation(), which will be called to re-process the type of the out-of-line definition of Y<T>::f() in a manner that *should* have made it match what's in the class template definition. It's very likely the case that the expression Y<T>::dim is not getting rebuilt properly.

	- Doug



More information about the cfe-dev mailing list