From 8397a44bedf542b53284674c87268819f4911d31 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 22 Feb 2012 16:17:30 +0100 Subject: QByteArray: deprecate QT_NO_CAST_FROM_BYTEARRAY-protected operators The QByteArray::operator const {char,void}*() implicit conversions are a source of subtle bugs, so they right- fully can be disabled with QT_NO_CAST_FROM_BYTEARRAY. const char *d = qstring.toLatin1(); // implicit conversion while ( d ) // oops: d points to freed memory // ... But almost no-one ever enabled this macros in the wild and many were bitten by these implicit conversions, so this patch deprecates them. I would have liked to remove them completely, but there are just too many occurrences even in Qt itself to hope to find all conditionally-compiled code that uses these. Also fixes all code that needs to compile under QT_NO_DEPRECATED (in qmake/, src/tools/). I984706452db7d0841620a0f64e179906123f3849 separately deals with the bulk of changes in src/ and examples/. Depends on I5ea1ad3c96d9e64167be53c0c418c7b7dba51f68. Change-Id: I8d47e6c293c80f61c6288c9f8d42fda41afe2267 Reviewed-by: David Faure Reviewed-by: Lars Knoll --- src/corelib/tools/qbytearray.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/corelib/tools/qbytearray.h') diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 8202097da5..09c43988fd 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -207,8 +207,10 @@ public: void squeeze(); #ifndef QT_NO_CAST_FROM_BYTEARRAY - operator const char *() const; - operator const void *() const; +#if QT_DEPRECATED_SINCE(5, 0) + QT_DEPRECATED operator const char *() const { return constData(); } + QT_DEPRECATED operator const void *() const { return constData(); } +#endif #endif char *data(); const char *data() const; @@ -415,12 +417,6 @@ inline char QByteArray::operator[](uint i) const inline bool QByteArray::isEmpty() const { return d->size == 0; } -#ifndef QT_NO_CAST_FROM_BYTEARRAY -inline QByteArray::operator const char *() const -{ return d->data(); } -inline QByteArray::operator const void *() const -{ return d->data(); } -#endif inline char *QByteArray::data() { detach(); return d->data(); } inline const char *QByteArray::data() const -- cgit v1.2.3