summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qchar.h
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-08-25 14:21:30 +0200
committerhjk <hjk121@nokiamail.com>2014-10-02 16:26:14 +0200
commit7dd394a16c51d11cd3ce91e288253ad137190994 (patch)
tree915432b9ed48de11122a3bcccfd2b13c7c6d44aa /src/corelib/tools/qchar.h
parent37597494666e6968ba7b2d946cdaf357069ec0b3 (diff)
Add a macro to disable only some 8 bit/16 bit string conversions
This is an opt-in trade-off between type safety and user code convenience. QT_NO_CAST_FROM_ASCII is highly beneficial to avoid unintended conversions from 8 bit data with potentially "unsuitable" encodings to QString. However, it has the undesirable side-effect to require user code to wrap character and string literals in QLatin1Char(...) and QLatin1String(...) or use similar construction, cluttering the code significantly. This patch introduces a QT_RESTRICTED_CAST_FROM_ASCII macro that works almost as QT_NO_CAST_FROM_ASCII, except that it enables the QChar(char) constructor and adds an additional QString(const char (&ch)[N]) constructor that matches C++ string literals, but no arbitrary character pointers. This avoids a significant share of the need to clutter the user code by only a slight relaxation of the type-safety. [ChangeLog][QtCore][QString] Added QT_RESTRICTED_CAST_FROM_ASCII macro as less intrusive alternative to QT_NO_CAST_FROM_ASCII. Change-Id: Iac72f1f90f81fbcae9bfb1fe68b0fec6ffb36c50 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Kai Koehne <kai.koehne@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qchar.h')
-rw-r--r--src/corelib/tools/qchar.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h
index 4db09e0f82..dcbe3fb0c2 100644
--- a/src/corelib/tools/qchar.h
+++ b/src/corelib/tools/qchar.h
@@ -83,8 +83,10 @@ public:
#ifndef QT_NO_CAST_FROM_ASCII
QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(char c) : ucs(uchar(c)) { }
+#ifndef QT_RESTRICTED_CAST_FROM_ASCII
QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR explicit QChar(uchar c) : ucs(c) { }
#endif
+#endif
// Unicode information
enum Category