Community
cancel
Showing results for 
Search instead for 
Did you mean: 
soulyeller
Beginner
69 Views

An limitation of ICC

Hi,

I was using the icc compiler [icc (ICC) 11.1 20090630] to some program written by me. And I have found that I can compile the program with g++, but not with icc.

Here is the program:
#include

using namespace std;

template
struct type_trait_t {};

template
struct identy_trait_t
{
public:
static const size_t type_size=sizeof(TYPE);
};

struct type1_t;

typedef identy_trait_t type1_trait_t;

struct type1_t : public type1_trait_t {
public:
int i;
};

int main () {
return 0;
}

When I was compiling this program with icc, it complains:
error: incomplete type is not allowed
static const size_t type_size=sizeof(TYPE);
^
detected during instantiation of class "identy_trait_t [with TYPE=type1_t]" at line 19

I know that this could be just a limitation of the icc compiler. I am wondering whether intel can eliminate this limitation in the future version?

Thanks a lot!

Best,
Phil
0 Kudos
3 Replies
JenniferJ
Moderator
69 Views

Quoting - soulyeller
error: incomplete type is not allowed
static const size_t type_size=sizeof(TYPE);
^
detected during instantiation of class "identy_trait_t [with TYPE=type1_t]" at line 19
Thanks for posting a testcase with the issue. I can duplicate the problem on Linux. But on Windows even VS2010 beta complains about it.

This code didn't follow the C++ starndard for static const variable declaration. do you have such code in your real application and it works as expected?

Thanks,
Jennifer
JenniferJ
Moderator
69 Views

Please use the following work-around instead.

[cpp]struct type1_t;

template 
struct identy_trait_t
{
public:
	// static const unsigned int type_size=sizeof(TYPE); // removed
	static const unsigned int type_size; // new
};

typedef identy_trait_t type1_trait_t;

struct type1_t : public type1_trait_t {
public:
	int i;
};

template   // new
const unsigned int identy_trait_t::type_size = sizeof(TYPE); // new[/cpp]

Judith_W_Intel
Employee
69 Views


Section 5.3.3 of the standard says "The sizeof operator shall not be applied to an expression

that has function or incomplete type ..."

So the question is whether at the time of instantiation of the Base class in this example is

the template argument TYPE incomplete?

[cpp]template 
struct Base
{
    static const int type_size=sizeof(TYPE);
};

struct Derived;

struct Derived : public Base {};
[/cpp]

I think the answer is yes, and therefore this code is illegal.

Nonetheless since g++ accepts it we need to fix this as a Gnu compatibility bug.

Interestingly g++ gives an error (like us) if the forward declaration of

Derived is removed --- which certainly shouldn't change Derived from being incomplete

to complete. So I thinkyou aretaking advantage of a quirk (i.e. bug)

in the Gnu compiler.

Reply