From b417a509f5636161e9fb6beed19f32f7a40dac7c Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 11 Apr 2025 14:30:03 +0200 Subject: [PATCH] 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 --- src/qml/jsapi/qjsprimitivevalue.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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;