summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLucie GĂ©rard <lucie.gerard@qt.io>2021-07-01 13:34:55 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-07-02 10:31:56 +0000
commit6bce7a3c6cebe359f1bd78c89a8e7742ccd10d1f (patch)
treed2d1d949d7a521a3d964eb63f3f8474357351431 /src
parent09f57ee29f61f4eb89d01f356d23f2fa90817c9a (diff)
lupdate/clang: Print warnings in consistent order
This is for the warnings emitted in TranslationRelatedStore::isValid() Change-Id: Ifed2852d1b22cb1a87679ec73849140e3293e3e5 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit 3ef442a592da661a2680d7d27ccdd737fea4e35c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/linguist/lupdate/cpp_clang.cpp9
-rw-r--r--src/linguist/lupdate/cpp_clang.h26
2 files changed, 26 insertions, 9 deletions
diff --git a/src/linguist/lupdate/cpp_clang.cpp b/src/linguist/lupdate/cpp_clang.cpp
index f613431c7..b3e792ac8 100644
--- a/src/linguist/lupdate/cpp_clang.cpp
+++ b/src/linguist/lupdate/cpp_clang.cpp
@@ -443,8 +443,15 @@ void ClangCppParser::loadCPP(Translator &translator, const QStringList &files, C
void ClangCppParser::collectMessages(TranslatorMessageVector &result,
TranslationRelatedStore &store)
{
- if (!store.isValid(true))
+ if (!store.isValid(true)) {
+ if (store.lupdateWarning.isEmpty())
+ return;
+ // The message needs to be added to the results so that the warning can be ordered
+ // and printed in a consistent way.
+ // the message won't appear in the .ts file
+ result.push_back(translatorMessage(store, store.lupdateIdMetaData, false, false, true));
return;
+ }
qCDebug(lcClang) << "---------------------------------------------------------------Filling translator for " << store.funcName;
qCDebug(lcClang) << " contextRetrieved " << store.contextRetrieved;
diff --git a/src/linguist/lupdate/cpp_clang.h b/src/linguist/lupdate/cpp_clang.h
index eeab83b9b..0523222cc 100644
--- a/src/linguist/lupdate/cpp_clang.h
+++ b/src/linguist/lupdate/cpp_clang.h
@@ -99,19 +99,21 @@ struct TranslationRelatedStore
QString lupdateWarning;
clang::SourceLocation sourceLocation;
- bool isValid(bool printwarning = false) const
+ bool isValid(bool printwarning = false)
{
switch (trFunctionAliasManager.trFunctionByName(funcName)) {
// only one argument: the source
case TrFunctionAliasManager::Function_Q_DECLARE_TR_FUNCTIONS:
if (contextArg.isEmpty()) {
if (printwarning) {
- std::cerr << qPrintable(lupdateLocationFile) << ":"
+ std::stringstream warning;
+ warning << qPrintable(lupdateLocationFile) << ":"
<< lupdateLocationLine << ":"
<< locationCol << ": "
<< " \'" << qPrintable(funcName)
<< "\' cannot be called without context."
<< " The call is ignored." <<std::endl;
+ lupdateWarning.append(QString::fromStdString(warning.str()));
}
return false;
}
@@ -120,12 +122,14 @@ struct TranslationRelatedStore
case TrFunctionAliasManager::Function_trUtf8:
if (lupdateSource.isEmpty()) {
if (printwarning) {
- std::cerr << qPrintable(lupdateLocationFile) << ":"
+ std::stringstream warning;
+ warning << qPrintable(lupdateLocationFile) << ":"
<< lupdateLocationLine << ":"
<< locationCol << ": "
<< " \'" << qPrintable(funcName)
<< "\' cannot be called without source."
<< " The call is ignored." << std::endl;
+ lupdateWarning.append(QString::fromStdString(warning.str()));
}
return false;
}
@@ -140,12 +144,14 @@ struct TranslationRelatedStore
case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3_UTF8:
if (contextArg.isEmpty() || lupdateSource.isEmpty()) {
if (printwarning) {
- std::cerr << qPrintable(lupdateLocationFile) << ":"
+ std::stringstream warning;
+ warning << qPrintable(lupdateLocationFile) << ":"
<< lupdateLocationLine << ":"
<< locationCol << ": "
<< " \'" << qPrintable(funcName)
<< "\' cannot be called without context or source."
<< " The call is ignored." << std::endl;
+ lupdateWarning.append(QString::fromStdString(warning.str()));
}
return false;
}
@@ -157,12 +163,14 @@ struct TranslationRelatedStore
case TrFunctionAliasManager::Function_QT_TRID_NOOP:
if (lupdateId.isEmpty()) {
if (printwarning) {
- std::cerr << qPrintable(lupdateLocationFile) << ":"
+ std::stringstream warning;
+ warning << qPrintable(lupdateLocationFile) << ":"
<< lupdateLocationLine << ":"
<< locationCol << ": "
<< " \'" << qPrintable(funcName)
<< "\' cannot be called without Id."
<< " The call is ignored." << std::endl;
+ lupdateWarning.append(QString::fromStdString(warning.str()));
}
return false;
}
@@ -170,12 +178,14 @@ struct TranslationRelatedStore
default:
if (funcName == QStringLiteral("TRANSLATOR") && lupdateComment.isEmpty()) {
if (printwarning) {
- std::cerr << qPrintable(lupdateLocationFile) << ":"
+ std::stringstream warning;
+ warning << qPrintable(lupdateLocationFile) << ":"
<< lupdateLocationLine << ":"
<< locationCol << ": "
- << " \'" << qPrintable(funcName)
- << "\' cannot be called without comment."
+ << qPrintable(funcName)
+ << " cannot be called without comment."
<< " The call is ignored." << std::endl;
+ lupdateWarning.append(QString::fromStdString(warning.str()));
}
return false;
}