QtQml: Avoid maybe-uninitialized warnings in QJSPrimitiveValue

The compiler can't see that we only access m_string if it has
previously been initialized. However, we can just zero the storage on
construction.

Pick-to: 6.9 6.8 6.5
Fixes: QTBUG-135367
Change-Id: I1b04d81e18063650501bdc24474c9672e999189d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Ulf Hermann 2025-04-11 14:30:03 +02:00
parent 53bd0bb6b0
commit b417a509f5
1 changed files with 5 additions and 1 deletions

View File

@ -932,10 +932,14 @@ private:
}
union {
bool m_bool = false;
bool m_bool;
int m_int;
double m_double;
QString m_string;
// Dummy value to trigger initialization of the whole storage.
// We don't want to see maybe-uninitialized warnings every time we access m_string.
std::byte m_zeroInitialize[sizeof(QString)] = {};
};
Type m_type = Undefined;