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

Bug

Alex_K_4
Beginner
390 Views

Usage of static constexpr member-function or member-variable, declared within a template, causes compiler error, if declared member-function or member-variable is further used within the same template.

Platform: Win 7, x86, Intel Parallel Studio 15 Update 6

Example:

template<typename T, int n> class test_template

{

public:

static constexpr int double_sz() {

return 2 * n;

}

T arr[double_sz()];

};

Here static constexpr member-function double_sz() is further used to define the size of array, declared within the same template. Result: compiler error "function call must have a constant value in a constant expression". 

 

0 Kudos
3 Replies
Garipov__Ruslan
Beginner
390 Views

I got the same issue in Intel C++ 16 Update 2. It's described in my post @ stackoverflow.

Do we have any chance to get a reply from Intel team's member?

0 Kudos
Anoop_M_Intel
Employee
390 Views

I can reproduce the problem which you report. I will escalate this to engineering and keep you posted on their update:

template<typename T, int n> class test_template
{
  public:
    static constexpr int double_sz() {
       return 2 * n;
    }
  T arr[double_sz()];
};
test_template<int,10> foo;

>icl /c static.cpp /Qstd=c++11

Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.6.285 Build 20151119
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

static.cpp
static.cpp(13): error: function call must have a constant value in a constant expression
  T arr[double_sz()];
        ^
          detected during instantiation of class "test_template<T, n> [with T=int, n=10]" at line 17

compilation aborted for static.cpp (code 2)

Thanks and Regards
Anoop

0 Kudos
Judith_W_Intel
Employee
390 Views

 

A possible workaround would be to use a constexpr variable instead of a constexpr routine, i.e.:

  static constexpr int double_sz = 2 *n;
  T arr[double_sz];


 

 

0 Kudos
Reply