Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

icc compiles incorrect code

Bert_Jonson
Beginner
374 Views

[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
Honored Contributor III
374 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)

0 Kudos
Bert_Jonson
Beginner
374 Views

It's C++11 feature.

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

0 Kudos
Judith_W_Intel
Employee
374 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

0 Kudos
Reply