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

Possible bug: incorrect member value

Tamir_A_
Beginner
316 Views

This program prints 0, when it, clearly, should print 11.

#include <stdio.h>

struct S0 {
    int t = 11;
};

struct S2 : virtual S0 {
};

S2 g_1[1];

int main(int argc, char* argv[])
{
    printf("%d", g_1[0].t);
}

This code compiled with the follow command on windows:

iclvars.bat intel64 & icl file.cpp /w /link /out:file.exe

Version:

Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.3.207 Build 20160415

 

0 Kudos
3 Replies
Viet_H_Intel
Moderator
316 Views

 

Have you gotten this error when compiling the above code?

file.cpp(5): error: data member initializer is not allowed

      int t = 11;
            ^

Thanks,

Viet

0 Kudos
Tamir_A_
Beginner
316 Views

Hello,

In this version (Intel(R) 64, Version 16.0.3.207 Build 20160415) this code compiled without an error.

the problem was that the program printed "0" instead of "11".

Regards,

Tamir Aviv.

0 Kudos
Judith_W_Intel
Employee
316 Views

 

Viet this program uses field initializers which is a C++11 feature only available if your reference compiler is MSVC++ 2013 or later or if you use the /Qstd=c++11 or /Qvc12 or /Qvc14 options.

Anyway I can reproduce the problem with 16.0 but it is fixed in 17.0 so please upgrade to get the fix for this... Sorry for the inconvenience.

Judy

0 Kudos
Reply