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>bb10
parent
a71b9c9377
commit
ae0b080c01
|
|
@ -56,14 +56,24 @@ QT_BEGIN_NAMESPACE
|
|||
// core language feature, so just use u"" here unconditionally:
|
||||
|
||||
#define QT_UNICODE_LITERAL(str) u"" str
|
||||
#define QStringLiteral(str) \
|
||||
(QString(QStringPrivate(nullptr, \
|
||||
const_cast<char16_t *>(QT_UNICODE_LITERAL(str)), \
|
||||
sizeof(QT_UNICODE_LITERAL(str))/2 - 1))) \
|
||||
/**/
|
||||
|
||||
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(QtPrivate::qMakeStringPrivate(QT_UNICODE_LITERAL(str)))) \
|
||||
/**/
|
||||
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QSTRINGLITERAL_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue