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

Buggy behavior in constexpr memeber variable

Park__Chae-Yeun
Beginner
1,457 Views

Hi,

 

I found that intel c++ compiler behaves suspiciously for constexpr member variable of a template class. With 

$ icpc -v
icpc version 19.0.5.281 (gcc version 8.3.0 compatibility)

The following code print nothing.

#include <iostream>
template<typename T>
struct Derived
{
	constexpr static char test_[] = "test";
};
/* These lines are useless in C++17
template<typename T>
constexpr char Derived<T>::test_[];
*/
int main()
{
	std::cout << Derived<double>::test_ << std::endl; //print nothing
	return 0;
}

I just used '-std=c++17' option. GCC version 8 compiles the code and print "test" as expected. I strongly suspect that GCC's behavior is the standard and ICC is buggy.

In addition, ICC version 2019.3.199 does not compile the code and print error "incomplete type is not allowed".

 

Best,

 

 

 

0 Kudos
5 Replies
RahulV_intel
Moderator
1,457 Views

Hi,

Thanks for reporting this bug. We will take this issue to the concerned team.

I have tried to reproduce this issue with icpc version 19.1 20200303. 

With icpc, -std=c++17 flag, I'm able to compile the code, but it doesn't print anything. With gcc it prints the output correctly.

However, with icpc and -std=c++14, the code compiles and prints the output correctly after adding "constexpr char Derived<T>::test_[];" (Commented part of your code).

 

--Rahul

0 Kudos
Viet_H_Intel
Moderator
1,457 Views

I've reported this bug to our Compiler Developer. Thanks,

0 Kudos
Park__Chae-Yeun
Beginner
1,457 Views

Dear Rahul and Viet,

 

Thanks for your quick responses. I also found that the polymorphic feature of the cereal c++ library (https://uscilab.github.io/cereal/polymorphism.html) does not work because of this issue. I hope it to be fixed in the next release of icc.

 

Best,

Chae-Yeun

0 Kudos
PrasanthD_intel
Moderator
1,260 Views

Hi,

 

The error you have reported on icc/icpc will be fixed in future releases.

Meanwhile, we have tried your sample code with icpx and didn't see any issue.

Please try icpx and let us know if that helps.

 

Regards

Prasanth

0 Kudos
GouthamK_Intel
Moderator
1,205 Views

Hi,

As we have not heard back from you, we are closing this thread. So we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only 

Have a Good day!


Thanks & Regards

Goutham


0 Kudos
Reply