- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
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
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
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
static const size_t type_size=sizeof(TYPE);
^
detected during instantiation of class "identy_trait_t
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please use the following work-around instead.
[cpp]struct type1_t; templatestruct 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]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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]templatestruct 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
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page