diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2021-08-04 10:11:55 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2021-08-04 19:36:01 -0700 |
commit | ae0b080c019025c2a949cf9468294ecf2b4eacb1 (patch) | |
tree | 4313824db51479d9dcd828b6e162cf814b280b40 /src | |
parent | a71b9c937719bc3a5f4de6e91dbdbe364df38cac (diff) |
QStringLiteral: suppress the clang-tidy warning about const_cast
We can't add the comment inside the macro, so we solve the problem by
adding an extra level of indirection.
Pick-to: 6.2
Change-Id: Ib8fbfcfeb48a49ca945dfffd169829b3610f6a34
Reviewed-by: Rui Oliveira
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/text/qstringliteral.h | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/corelib/text/qstringliteral.h b/src/corelib/text/qstringliteral.h index d86e6eafd9..d9804b31d6 100644 --- a/src/corelib/text/qstringliteral.h +++ b/src/corelib/text/qstringliteral.h @@ -56,13 +56,23 @@ QT_BEGIN_NAMESPACE // core language feature, so just use u"" here unconditionally: #define QT_UNICODE_LITERAL(str) u"" str + +using QStringPrivate = QArrayDataPointer<char16_t>; + +namespace QtPrivate { +template <qsizetype N> +static Q_ALWAYS_INLINE QStringPrivate qMakeStringPrivate(const char16_t (&literal)[N]) +{ + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) + auto str = const_cast<char16_t *>(literal); + return { nullptr, str, N - 1 }; +} +} + #define QStringLiteral(str) \ - (QString(QStringPrivate(nullptr, \ - const_cast<char16_t *>(QT_UNICODE_LITERAL(str)), \ - sizeof(QT_UNICODE_LITERAL(str))/2 - 1))) \ + (QString(QtPrivate::qMakeStringPrivate(QT_UNICODE_LITERAL(str)))) \ /**/ -using QStringPrivate = QArrayDataPointer<char16_t>; QT_END_NAMESPACE |