Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
27 Views

Virtual functions / anonymous classes (wrong code)

Hi,

I encountered a problem concerning virtual functions and anonymous classes. I'm not sure whether this is due to a compiler bug or just illegal C++ code (see also http://stackoverflow.com/questions/2082339/virtual-tables-on-anonymous-classes). Anyway, the problem only occurs when the program given below is compiled with the C++ Compiler which is part of Parallel Studio 2011 (Version 12.0.0.063, Build 20100721), but it does not occur when using the Intel C++ Compiler for Linux (Version 11.1, 20100806) or GCC 4.5.1. If it's illegal C++ code, I would suggest to let the compiler emit at least a warning.

Kind regards,
Peter


#include

using namespace std;

class base {
public:
virtual void test() = 0;
};

class foo: public base {
public:
void test() {cout << "foo " << endl;}
};

class bar: public base {
public:
void test() {cout << "bar " << endl;}
};

int main() {
class: public foo {} f1;
// b1 is never used, but must exist to produce the error
class: public bar {} b1;

// prints "foo", okay!
(static_cast(&f1))->test();

// prints "bar", wrong!
base* temp1 = static_cast(&f1);
temp1->test();

// ==================================================

class foo2: public foo {} f2;

// prints "foo", okay!
(static_cast(&f2))->test();

// prints "foo", okay!
base* temp2 = static_cast(&f2);
temp2->test();
}

0 Kudos
2 Replies
Highlighted
Moderator
27 Views

I've created a bug report based on this testcase.

The link you provided http://stackoverflow.com/questions/2082339/virtual-tables-on-anonymous-classes has a slightly different test, icl gives an internal error. I'll also report it as well to get the internal error fixed.

Thanks for reporting.
Jennifer

0 Kudos
Highlighted
Moderator
27 Views

Updated info on the virtual function issue and the other internal error one. Both are fixed and should be in the next Update 2 release. The issues are DPD200161465, DPD200161467(Internal Error).

Please watch the email notification from Intel Premier Support around end of Jan or early Feb 2011 about the update 2 release. When update 2 is release, our fixes listshould show the issue IDsonhttp://software.intel.com/en-us/articles/intel-composer-xe-2011-compilers-fixes-list/

Thanks,
Jennifer
0 Kudos