summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-11-12 13:22:02 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-11-13 21:51:29 +0100
commitf8ad329f7ee01993c388f78851fc4ac88f5093b4 (patch)
tree96d6bf0507b22c798d366a7a0a865567877d7e27
parent5b0d53863868dd9895cab7f37967a644baf3d586 (diff)
QCharRef: properly disable assignment from char
Under QT_NO_CAST_FROM_ASCII the assignment would fall back to operator=(int) after a promotion. Add a deleted overload to block this. (QChar itself uses a private constructor for the same purpose, but I chose the C++11 solution). Nothing to do in Qt 6, QCharRef is gone. Change-Id: Iba50ad2b6ad95d7c3a5e4920ab03fae5d3db0319 Fixes: QTBUG-88431 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Albert Astals Cid <aacid@kde.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/corelib/text/qstring.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index 5a4ac497e0..fe97279aaf 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -1231,6 +1231,10 @@ public:
{ return operator=(QChar::fromLatin1(c)); }
inline QT_ASCII_CAST_WARN QCharRef &operator=(uchar c)
{ return operator=(QChar::fromLatin1(c)); }
+#else
+ // prevent char -> int promotion, bypassing QT_NO_CAST_FROM_ASCII
+ QCharRef &operator=(char c) = delete;
+ QCharRef &operator=(uchar c) = delete;
#endif
inline QCharRef &operator=(const QCharRef &c) { return operator=(QChar(c)); }
inline QCharRef &operator=(ushort rc) { return operator=(QChar(rc)); }