- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
[cpp]template<int n> void foo(const int (&x)
int main()
{
int x[1][1] = {{0}};
foo(x);
}[/cpp]
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:
- 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.
- 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'.
- 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.
- 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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page