diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2022-06-20 08:56:31 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2022-06-23 10:41:22 +0200 |
commit | 8c60d2d28888321b7daa605a0cc6398104d7e0c0 (patch) | |
tree | 6ea4b0b3b7336f05decca1ee1657b3c13a505d59 | |
parent | 8b24485178ef69659d7d508cb92a288bb44459c0 (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.cpp | 2 | ||||
-rw-r--r-- | tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp | 11 | ||||
-rw-r--r-- | tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result | 13 |
3 files changed, 24 insertions, 2 deletions
diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp index 1db88e63b..0a940ef04 100644 --- a/src/linguist/lupdate/cpp.cpp +++ b/src/linguist/lupdate/cpp.cpp @@ -1970,8 +1970,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 6d2dde8c8..afa0efd8b 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 @@ void testing::test() { static const char * const test_string_n3[] = { 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 631d5cefd..0272f9dad 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result @@ -414,6 +414,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> <location filename="finddialog.cpp" line="168"/> |