Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Bert_Jonson
Beginner
43 Views

icc compiles incorrect code

[cpp]struct A {
int a = 10;
};

struct S {
union {
A a;
};
};


int main() {

S s;

return 0;
}[/cpp]

GCC gives an error:

error: use of deleted function 'S::S()'

ICC 13 update 1 on win compiles the code, but it mustn't because there is shadow using of A::A() ctor when union is not initialized.

0 Kudos
3 Replies
TimP
Black Belt
43 Views

$ g++ bj.cpp
bj.cpp:3:11: error: ISO C++ forbids initialization of member ‘a’
bj.cpp:3:11: error: making ‘a’ static
bj.cpp:3:11: error: ISO C++ forbids in-class initialization of non-const static
member ‘a’

$ icl bj.cpp
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Ve
rsion 13.1.0.149 Build 20130118
Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

bj.cpp
bj.cpp(3): error: data member initializer is not allowed
    int a = 10;
          ^

compilation aborted for bj.cpp (code 2)

Bert_Jonson
Beginner
43 Views

It's C++11 feature.

Please, try with -std=c++0x and /Qstd=c++0x.

Judith_W_Intel
Employee
43 Views

 

Since we have only partially implemented c++11 non static data member initialization (i.e. we only allow scalar iniitialization) I think the example code is initialized correctly and therefore no error is needed or issued.

Judy