dimanche 26 février 2017

Brace-or-equal-initializers on anonymous struct does not work on VS2013

Brace-or-equal-initializers in an anonymous struct within a struct doesn't do their work on output produced by VS2013. There's the code:

#include <iostream>
#include <cstdint>


struct S
{
    struct
    {
        uint64_t val = 0;
    }anon;
};

int main()
{
    S s;
    S *a = new S;

    std::cout << s.anon.val << std::endl;
    std::cout << a->anon.val << std::endl;

    return 0;
}

Compile with this command on Linux:

g++ -std=c++11 def-init-anon-atruct.cpp -o def-init-anon-atruct

(Adding optimisation flags does not affect the result)

Expected result:

0
0

Weird. Running that with VS2013 gives garbage values. Who's right on this one in terms of implementing C++11 standards right? I highly doubt this is GCC's fault.

Is it something to do with some useless VS compiler options? Windows extensions? I have to make default constructors for the structures because of a bug MS made? this is absurd.

Aucun commentaire:

Enregistrer un commentaire