Warning, /sdk/clazy/docs/checks/README-qstring-arg.md is written in an unsupported language. File is not indexed.
0001 # qstring-arg 0002 0003 Implements three warnings: 0004 0005 1. Detects when you're using chained `QString::arg()` calls and should instead use the multi-arg overload to save memory allocations 0006 0007 QString("%1 %2").arg(a).arg(b); 0008 QString("%1 %2").arg(a, b); // one less temporary heap allocation 0009 0010 2. Detects when you're passing an integer to QLatin1String::arg() as that gets implicitly cast to QChar. 0011 It's preferable to state your intention and cast to QChar explicitly. 0012 0013 3. Detects when you're using misleading `QString::arg()` overloads 0014 0015 QString arg(qlonglong a, int fieldwidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const 0016 QString arg(qulonglong a, int fieldwidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const 0017 QString arg(long a, int fieldwidth = 0, int base=10, QChar fillChar = QLatin1Char(' ')) const 0018 QString arg(ulong a, int fieldwidth = 0, int base=10, QChar fillChar = QLatin1Char(' ')) const 0019 QString arg(int a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const 0020 QString arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const 0021 QString arg(short a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const 0022 QString arg(ushort a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const 0023 QString arg(double a, int fieldWidth = 0, char fmt = 'g', int prec = -1, QChar fillChar = QLatin1Char(' ')) const 0024 QString arg(char a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const 0025 QString arg(QChar a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const 0026 QString arg(const QString &a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const 0027 0028 because they are commonly misused, for example: 0029 0030 int hours = ...; 0031 int minutes = ...; 0032 // This won't do what you think it would at first glance. 0033 QString s("The time is %1:%2").arg(hours, minutes); 0034 0035 To reduce false positives, some cases won't be warned about: 0036 0037 str.arg(hours, 2); // User explicitly used a integer literal, it's probably fine 0038 str.arg(foo); // We're only after cases where the second argument (or further) is specified, so this is safe 0039 str.arg(foo, width); // Second argument is named width, or contains the name "width", it's safe. Same for third argument and "base". 0040 0041 Using these misleading overloads is perfectly valid, so only warning (1) is enabled by default. 0042 To enable warning (2), `export CLAZY_EXTRA_OPTIONS="qstring-arg-fillChar-overloads"`