aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-04-11 14:30:03 +0200
committerUlf Hermann <ulf.hermann@qt.io>2025-04-15 14:27:14 +0200
commitb417a509f5636161e9fb6beed19f32f7a40dac7c (patch)
tree113c7e251260e83748b6d0e1850a99da2ff5016c /src/qml/jsapi
parent53bd0bb6b06c2d4b4570d22f41dfe3951db785ba (diff)
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>
Diffstat (limited to 'src/qml/jsapi')
-rw-r--r--src/qml/jsapi/qjsprimitivevalue.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/qml/jsapi/qjsprimitivevalue.h b/src/qml/jsapi/qjsprimitivevalue.h
index 3551eca358..5981bcf23a 100644
--- a/src/qml/jsapi/qjsprimitivevalue.h
+++ b/src/qml/jsapi/qjsprimitivevalue.h
@@ -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;