Quantcast
Viewing all articles
Browse latest Browse all 22162

struct uninitialization issue in c++

I have following struct whose member is another struct:

struct SA {    ...};struct S {    SA a;    ...};

And in the code I need to reset struct frequently, with:

// data memberS m_s;// member functionvoid clear() {    m_s.a = {};    m_s.b = {};    ...}

I'm using gcc version 7.3.1. With debug build, this works fine, with release build, it fails with:

error: '<anonymous>' is used uninitialized in this function [-Werror=uninitialized]

Why is this error, it is a defined way of initialize data to zero, right?If I change to :

void clear() {    SA sa{};    m_s.a = sa;    m_s.b = {};    ...}

instead, the release build will succeed.


Viewing all articles
Browse latest Browse all 22162

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>