- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @ all,
I am using constexpr if widely within my code. After a successfull build with the gcc I wanted to use *the good stuff*, namely icpc.
Here is a short example of my code:
/*...*/ virtual inline void run( ) override { #pragma omp parallel for for( std::size_t i = 0; i < REP_COUNT; ++i ) { //... if constexpr( ( PROCESS_DATA_COUNT / 4 ) >= 2 ) { //... } if constexpr( ( PROCESS_DATA_COUNT / 4 ) == 4 ) { //... } } } /*...*/
When I try to compile it with the icpc (Version 18.0.0.128 Build 20170811), it breaks with the following output:
/usr/include/c++/7/bits/stl_pair.h(79): error: inline specifier allowed on function declarations only
_GLIBCXX17_INLINE constexpr piecewise_construct_t piecewise_construct =
^/usr/include/c++/7/utility(345): error: inline specifier allowed on function declarations only
inline constexpr in_place_t in_place{};
^... error: expected a "("
if constexpr( ( PROCESS_DATA_COUNT / 4 ) >= 2 ) {
^
Is there no constexpr if within the newest icpc? Is there a proper workaround?
Sincerely yours
- Tags:
- CC++
- Development Tools
- Intel® C++ Compiler
- Intel® Parallel Studio XE
- Intel® System Studio
- Optimization
- Parallel Computing
- Vectorization
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
'consexpr if' is not listed in Supported Features- https://software.intel.com/en-us/articles/c17-features-supported-by-intel-c-compiler
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It might not be listed but the relevant question is when it is going to get implemented.
If I remember correctly, it has been stated that version 18 won't support constexpr-if at all, so we have to wait until next year.
This is unfortunate (for Intel) because it's one of the most asked features. And yes there are workarounds (Which I prefer not to use):
template specialization, enable_if and so on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FWIW
Even without "if constexpr(...)" any good compiler optimization when given "if(expression that is constant at compile time)" should be able to optimize out the code section(s) that will never be entered.
Why invent a new syntax that is not needed?
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it for sure, that the "invalid" branch will never be compiled? For instance if I have two lets called it "flavors" of a method, depending on some template parameter, i can use SFINAE to realize the behaviour I want. But it's a bit smelly I think.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To help the rest of us, the official C++17 document number is P0292R2. It would be great to know whether the next update to 18.0 will support compile time if (if constexpr). Does anyone have a response from Intel?

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