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-07-15 11:12:32 +0200
commit4b4f38d2663185eb4353667bb5fb75dbc0ac26cb (patch)
treed9985e6128a2e4e59fa39d4570eba416cdb25924
parent7dd7954a50c8e64b898df38b47ad334f74261457 (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 068273cda..3c421b28a 100644
--- a/src/linguist/lupdate/cpp.cpp
+++ b/src/linguist/lupdate/cpp.cpp
@@ -1967,8 +1967,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 d93f1bb1f..03d8d9f5a 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
@@ -688,3 +688,14 @@ class testing {
QT_TR_N_NOOP("%n test");
};
};
+
+
+
+// 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 7c500f6a3..cdda8897f 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
@@ -417,6 +417,19 @@ backslashed \ stuff.</source>
</message>
</context>
<context>
+ <name>QTBUG99415</name>
+ <message>
+ <location filename="main.cpp" line="697"/>
+ <source>text1</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="701"/>
+ <source>text2</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
<name>QTranslator</name>
<message numerus="yes">
<location filename="finddialog.cpp" line="168"/>