1

I've got some code parsing json like so:

  QJsonParseError errors;
  auto doc = QJsonDocument::fromJson(myJson.toUtf8(), &errors);

Resharper's clang tidy suggestions flags that QJsonParseError errors is an 'uninitialized record type'

The suggested fix is to zero initialize the variable via {} for C++11. The autofix offered by resharper, puts in some brackets like: QJsonParseError errors{};

What does that actually mean/do?

CaptRespect
  • 1,985
  • 1
  • 16
  • 24

1 Answers1

1

Zero initialization guarantees that the members of a class/struct are zero initialized. For example -

struct student
{
    int idNo;
    char name[20];
};

So, if object of student is zero-initialized, then it is guaranteed that the member variables idNo, name value(s) are initialized with zeroes (i.e., idNo = 0 and name array filled with zeroes).

In your case, QJsonParseError members are zero initialized rather than filling with some random values during object initialization.

Mahesh
  • 34,573
  • 20
  • 89
  • 115