Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Park__Chae-Yeun
Beginner
114 Views

Buggy behavior in constexpr memeber variable

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
3 Replies
RahulV_intel
Moderator
114 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

Viet_H_Intel
Moderator
114 Views

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

Park__Chae-Yeun
Beginner
114 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