Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
7783 Discussions

ICC 17.0.2 rejects valid C++ template function specialization

Matthias_H_3
Beginner
346 Views

The following code is rejected with the message
test.cpp(19): error: declaration is incompatible with function template "void Foo::bar(Vec<, T>) [with N=0]" (declared at line 11) void Foo<0>::bar(Vec<0, T> x) {}

Compiled with: icpc -std=c++14 test.cpp
icpc --version
icpc (ICC) 17.0.2 20170213
Copyright (C) 1985-2017 Intel Corporation. All rights reserved.

constexpr int getN(int n) {
    return n;
};

template<int N, typename T>
struct Vec{ };

template<int N>
struct Foo 
{
  template<typename T> void bar(Vec<getN(N), T> x); 

  //// A workaround
  // static constexpr int n = getN(N);
  // template<typename T> void bar(Vec<n, T> x); 
};

template<> template <typename T>
void Foo<0>::bar(Vec<0, T> x) {}

Thanks,
Matthias Hochsteger

 

0 Kudos
2 Replies
Matthias_H_3
Beginner
346 Views

One additional note:
It's working with -std=c++11 instead of -std=c++14

Matthias

Judith_W_Intel
Employee
346 Views

 

Yes this is a bug and is a duplicate of an existing bug in our database (DPD200416934).

The good news is that it's already fix in our development compiler - the bad news is that the change is too risky to go into 17.0.

It will be fixed in the next 18.0 beta update and of course the final 18.0 release.

Thanks for reporting it. I'm glad you were able to come up with a workaround... 

Reply