Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7873 Discussions

bug-report: template function argument deduction



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:

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

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 [cpp]template<class T> void foo(const T (&x)[1][1]) {}[/cpp] 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.

0 Kudos
2 Replies
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
0 Kudos

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.

0 Kudos