icc compiles incorrect code

icc compiles incorrect code

struct A {
 int a = 10;
struct S {
 union {
 A a;
int main() {
S s;
return 0;

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.

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

$ 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 Build 20130118
Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

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

compilation aborted for bj.cpp (code 2)

It's C++11 feature.

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


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.


Leave a Comment

Please sign in to add a comment. Not a member? Join today