summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2022-06-20 08:56:31 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2022-06-23 10:40:48 +0200
commit18a38fe6520da67a51c39c56b2a6156727454b75 (patch)
treed1498b5f21dd13691162b00201fd1288d00b56bf
parent1364c1363406eda9b462f4e48ed09248ae0cdaf8 (diff)
lupdate: Allow multiple specifiers after method signature
...in the old C++ parser. Out of line method definitions with multiple specifiers resulted in an lupdate warning. Example: class MyClass { Q_OBJECT QString text() const noexcept; } QString MyClass::text() const noexcept { return tr("foo"); } The reason was that we discarded the prospective context ("MyClass") after encountering two consecutive identifier tokens (const noexcept). Presumably, this was done to discard the context in the case of return types such as in: std::string myFunc() { return tr("foo").toStdString(); } The code discards the prospective context "std" upon encountering "myFunc". However, this is such an edge case, given that it's unlikely that people have a global tr function defined, we can happily allow this wrongness in favor of fixing the frequent occurrence of multiple specifiers after a parameter list. [ChangeLog][lupdate] lupdate does not trip anymore over tr() calls in methods with multiple specifiers. For example "QString MyClass::foo() const noexcept" now gets the correct context. Fixes: QTBUG-99415 Change-Id: I54afb96270fae1651dcf19fb9c479fa4cba3ede8 Reviewed-by: Kai Koehne <kai.koehne@qt.io> (cherry picked from commit afbc20ed01e187c1af6ae55f6a9a3a512b183f1c)
-rw-r--r--src/linguist/lupdate/cpp.cpp2
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp11
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result13
3 files changed, 24 insertions, 2 deletions
diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp
index adaed23de..d173da32f 100644
--- a/src/linguist/lupdate/cpp.cpp
+++ b/src/linguist/lupdate/cpp.cpp
@@ -1959,8 +1959,6 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac
} else {
notrfunc:
prefix.clear();
- if (yyTok == Tok_Ident && !yyParenDepth)
- prospectiveContext.clear();
}
metaExpected = false;
break;
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
index 2dfcb5903..555549379 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
@@ -698,3 +698,14 @@ class Hogus : QObject {
};
const QString Hogus::myString(QT_TR_NOOP("this should be in Hogus"));
+
+
+
+// QTBUG-99415: multiple specifiers after method parameter list
+class QTBUG99415 : QObject {
+ Q_OBJECT
+ const QString text1() const noexcept { return tr("text1"); }
+ const QString text2() const noexcept;
+};
+
+const QString QTBUG99415::text2() const noexcept { return tr("text2"); }
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
index 50274e913..f21258d87 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
@@ -422,6 +422,19 @@ backslashed \ stuff.</source>
</message>
</context>
<context>
+ <name>QTBUG99415</name>
+ <message>
+ <location filename="main.cpp" line="707"/>
+ <source>text1</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="711"/>
+ <source>text2</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
<name>QTranslator</name>
<message>
<location filename="finddialog.cpp" line="168"/>