bug-report: template function argument deduction

bug-report: template function argument deduction

Hello!

I came across an interesting compiler behaviour (which I believe to be a bug) when trying to compile a template function with a template-argument-dependent const-reference-to-multidimensional-array or const-pointer-to-multidimensional-array argument. I have reproduced this behaviour with various Linux versions of the Intel C++ compiler, namely: 10.1, 11.1, 12.1.3, 12.1.4 and 12.1.5.

Consider the following minimal example:

template<int n> void foo(const int (&x)[n][n]) {}
int main()
{
  int x[1][1] = {{0}};
  foo(x);
}

The Intel C++ Compiler aborts the compilation of the above code with the following error message:

error : no instance of function template "foo" matches the argument list

argument types are: (int [1][1])

Alternatively, replacing the above definition of 'foo' by

template<class T> void foo(const T (&x)[1][1]) {}
leads to the same compiler error.

I have made several observations regarding this issue, which I want to summarize shortly here:

  1. This behaviour only appears in template functions. Replacing the definition of 'foo' in the above example by a (matching) non-template function resolves the issue.
  2. Explicitly specifying the template argument for the call of 'foo' in line 5 also resolves the issue. This holds true for both the template<int n> as well as for the alternative template<class T> version of 'foo'.
  3. The function's argument has to be a reference (or a pointer) to a multi-dimensional array depending on at least one template argument. A version of the above example code using a one-dimensional array compiles just fine.
  4. The problem is somehow linked to the 'const' keyword. Either removing the 'const' keyword from the argument list of 'foo' in line 1 of the above example or declaring the variable 'x' in line 4 as 'const int' resolves the issue.

Best regards,

 - Peter Z.

3 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

Thanks for the small example and detailed analysis. I have entered this in our bug tracking database as DPD200236336 and someone should inform you when a fix is available.

Judy

Hi Peter,

The compiler no longer gives this error with Intel(R) C++ Composer XE 2013 update 1 and above. Let us know if you see any problems with the fix.

Brandon Hewitt Technical Consulting Engineer Tools Knowledge Base: "http://software.intel.com/en-us/articles/tools" Software Product Support info: "http://www.intel.com/software/support"

Accedere per lasciare un commento.