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

BUG For constexpr in Templates

Sam_D_
Beginner
347 Views

The following code does not compile with ICC (versions below) but does with GCC was already posted on StackOverflow

class Constants {   
   static constexpr int value_ = 2;

public:    
   static constexpr inline int V() { return value_; }    
};

typedef Constants CC;

template<int N>
class Terror {    
public:
  template<class T>
  void F(T (&a)[CC::V()]) {}
};

int main() {
  int array[CC::V()];    
  Terror<42> ter = Terror<42>();    
  ter.F(array);
}

Tested with:

Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.4.258 Build 20160811
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

and

Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.0.128 Build 20170811
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.
0 Kudos
3 Replies
TimP
Honored Contributor III
347 Views

Wasn't there a post recently indicating when constexpr implementation should be expected in icc?  Apparently, 16.0 had partial implementation but a full one hasn't released yet.

0 Kudos
Sam_D_
Beginner
347 Views

Okay, I must have missed that. I saw some other constexpr/template issues have been addressed. But since I tried Intel 18.0. I was a little disappointed ;)

0 Kudos
Judith_W_Intel
Employee
347 Views

 

I assume you are seeing the diagnostic below. This does look like a compiler bug. I have filed a bug report in our internal bugs database with ID cmplrs-46576. The problem is still present in our development compiler. Thanks for reporting it and creating a nice small example for us.

Judy

 

//bug.cpp
constexpr int V() { return 2; }

template<class T>
#ifdef OK
void F(T (&a)[2]) {}
#else
void F(T (&a)[V()]) {}
#endif

int main() {
  int array[2];
  F(array);
  return 0;
}

sptel42-1185> g++ -c bug.cpp
sptel42-1186> icpc -c bug.cpp
bug.cpp(13): error: no instance of function template "F" matches the argument list
            argument types are: (int [2])
 
    F(array);
    ^
bug.cpp(8): note: this candidate was rejected because at least one template argument could not be deduced
  void F(T (&a)[V()]) {}
       ^


compilation aborted for bug.cpp (code 2)

 

0 Kudos
Reply