- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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".
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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];
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page