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 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

$ 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)

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.

Judy

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui